Skip to content

Commit

Permalink
Migrate Promise interface to Kotlin (facebook#44587)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#44587

# Changelog:
[Internal] -

As in the title, moving towards migrating all the interfaces in react.bridge.

Differential Revision: https://internalfb.com/D57433401
  • Loading branch information
rshest authored and facebook-github-bot committed Aug 2, 2024
1 parent ea78d68 commit 2ab4c84
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.bridge;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
package com.facebook.react.bridge

/*
* Interface that represents a JavaScript Promise which can be passed to the native module as a
Expand All @@ -18,29 +15,28 @@
* will be marked as "promise" and will return a promise when invoked from JavaScript.
*/
public interface Promise {

/**
* Successfully resolve the Promise with an optional value.
*
* @param value Object
*/
void resolve(@Nullable Object value);
public fun resolve(value: Any?)

/**
* Report an error without an exception using a custom code and error message.
*
* @param code String
* @param message String
*/
void reject(String code, String message);
public fun reject(code: String, message: String?)

/**
* Report an exception with a custom code.
*
* @param code String
* @param throwable Throwable
*/
void reject(String code, Throwable throwable);
public fun reject(code: String, throwable: Throwable?)

/**
* Report an exception with a custom code and error message.
Expand All @@ -49,36 +45,35 @@ public interface Promise {
* @param message String
* @param throwable Throwable
*/
void reject(String code, String message, Throwable throwable);
public fun reject(code: String, message: String?, throwable: Throwable?)

/**
* Report an exception, with default error code. Useful in catch-all scenarios where it's unclear
* why the error occurred.
*
* @param throwable Throwable
*/
void reject(Throwable throwable);
public fun reject(throwable: Throwable)

/* ---------------------------
* With userInfo WritableMap
* --------------------------- */

/**
* Report an exception, with default error code, with userInfo. Useful in catch-all scenarios
* where it's unclear why the error occurred.
*
* @param throwable Throwable
* @param userInfo WritableMap
*/
void reject(Throwable throwable, WritableMap userInfo);
public fun reject(throwable: Throwable, userInfo: WritableMap)

/**
* Reject with a code and userInfo WritableMap.
*
* @param code String
* @param userInfo WritableMap
*/
void reject(String code, @NonNull WritableMap userInfo);
public fun reject(code: String, userInfo: WritableMap)

/**
* Report an exception with a custom code and userInfo.
Expand All @@ -87,7 +82,7 @@ public interface Promise {
* @param throwable Throwable
* @param userInfo WritableMap
*/
void reject(String code, Throwable throwable, WritableMap userInfo);
public fun reject(code: String, throwable: Throwable?, userInfo: WritableMap)

/**
* Report an error with a custom code, error message and userInfo, an error not caused by an
Expand All @@ -97,7 +92,7 @@ public interface Promise {
* @param message String
* @param userInfo WritableMap
*/
void reject(String code, String message, @NonNull WritableMap userInfo);
public fun reject(code: String, message: String?, userInfo: WritableMap)

/**
* Report an exception with a custom code, error message and userInfo.
Expand All @@ -107,18 +102,13 @@ public interface Promise {
* @param throwable Throwable
* @param userInfo WritableMap
*/
void reject(String code, String message, Throwable throwable, WritableMap userInfo);

/* ------------
* Deprecated
* ------------ */

/**
* Report an error which wasn't caused by an exception.
*
* @deprecated Prefer passing a module-specific error code to JS. Using this method will pass the
* error code "EUNSPECIFIED".
*/
@Deprecated
void reject(String message);
public fun reject(code: String?, message: String?, throwable: Throwable?, userInfo: WritableMap?)

/** Report an error which wasn't caused by an exception. */
@Deprecated(
message =
"""Prefer passing a module-specific error code to JS. Using this method will pass the
error code EUNSPECIFIED""",
replaceWith = ReplaceWith("reject(code, message)"))
public fun reject(message: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,35 @@ class ShareModuleTest {
this.value = value
}

override fun reject(code: String?, message: String?) {
override fun reject(code: String, message: String?) {
reject(code, message, null, null)
}

override fun reject(code: String?, throwable: Throwable?) {
override fun reject(code: String, throwable: Throwable?) {
reject(code, null, throwable, null)
}

override fun reject(code: String?, message: String?, throwable: Throwable?) {
override fun reject(code: String, message: String?, throwable: Throwable?) {
reject(code, message, throwable, null)
}

override fun reject(throwable: Throwable?) {
override fun reject(throwable: Throwable) {
reject(null, null, throwable, null)
}

override fun reject(throwable: Throwable?, userInfo: WritableMap?) {
override fun reject(throwable: Throwable, userInfo: WritableMap) {
reject(null, null, throwable, userInfo)
}

override fun reject(code: String?, userInfo: WritableMap) {
override fun reject(code: String, userInfo: WritableMap) {
reject(code, null, null, userInfo)
}

override fun reject(code: String?, throwable: Throwable?, userInfo: WritableMap?) {
override fun reject(code: String, throwable: Throwable?, userInfo: WritableMap) {
reject(code, null, throwable, userInfo)
}

override fun reject(code: String?, message: String?, userInfo: WritableMap) {
override fun reject(code: String, message: String?, userInfo: WritableMap) {
reject(code, message, null, userInfo)
}

Expand All @@ -153,7 +153,7 @@ class ShareModuleTest {
}

@Deprecated("Method deprecated")
override fun reject(message: String?) {
override fun reject(message: String) {
reject(null, message, null, null)
}
}
Expand Down

0 comments on commit 2ab4c84

Please sign in to comment.