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:
Satyajit Sahoo
2016-01-25 12:34:06 -08:00
committed by facebook-github-bot-9
parent ea1aec3c23
commit 0007bff977
3 changed files with 11 additions and 9 deletions

View File

@@ -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"));
}
}