Use promises in 'SourceCodeModule'
Summary: Closes https://github.com/facebook/react-native/pull/5504 Reviewed By: svcscm Differential Revision: D2861158 Pulled By: dmmiller fb-gh-sync-id: 3e9c257288539183f6156b8d360b54dc570bc7ad
This commit is contained in:
parent
ea1aec3c23
commit
0007bff977
|
@ -39,7 +39,7 @@ function fetchSourceMap(): Promise {
|
|||
return Promise.reject(new Error('RCTNetworking module is not available'));
|
||||
}
|
||||
|
||||
return new Promise(RCTSourceCode.getScriptText)
|
||||
return RCTSourceCode.getScriptText()
|
||||
.then(extractSourceMapURL)
|
||||
.then((url) => {
|
||||
if (url === null) {
|
||||
|
|
|
@ -24,15 +24,17 @@ RCT_EXPORT_MODULE()
|
|||
- (void)setScriptText:(NSString *)scriptText {}
|
||||
#endif
|
||||
|
||||
RCT_EXPORT_METHOD(getScriptText:(RCTResponseSenderBlock)successCallback
|
||||
failureCallback:(RCTResponseErrorBlock)failureCallback)
|
||||
NSString *const RCTErrorUnavailable = @"E_SOURCE_CODE_UNAVAILABLE";
|
||||
|
||||
RCT_EXPORT_METHOD(getScriptText:(RCTPromiseResolveBlock)resolve
|
||||
reject:(RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
if (RCT_DEV && self.scriptData && self.scriptURL) {
|
||||
NSString *scriptText = [[NSString alloc] initWithData:self.scriptData encoding:NSUTF8StringEncoding];
|
||||
|
||||
successCallback(@[@{@"text": scriptText, @"url": self.scriptURL.absoluteString}]);
|
||||
resolve(@[@{@"text": scriptText, @"url": self.scriptURL.absoluteString}]);
|
||||
} else {
|
||||
failureCallback(RCTErrorWithMessage(@"Source code is not available"));
|
||||
reject(RCTErrorUnavailable, nil, RCTErrorWithMessage(@"Source code is not available"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import javax.annotation.Nullable;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
|
@ -35,14 +35,14 @@ public class SourceCodeModule extends BaseJavaModule {
|
|||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "RKSourceCode";
|
||||
return "RCTSourceCode";
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getScriptText(final Callback onSuccess, final Callback onError) {
|
||||
public void getScriptText(final Promise promise) {
|
||||
WritableMap map = new WritableNativeMap();
|
||||
map.putString("fullSourceMappingURL", mSourceMapUrl);
|
||||
onSuccess.invoke(map);
|
||||
promise.resolve(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue