Permalink
Browse files

Add completion callback to enqueueJSCall

Reviewed By: majak

Differential Revision: D3423580

fbshipit-source-id: c063c9c5d8961d5c9cb14c32d70767c67d78430a
  • Loading branch information...
1 parent 7fa677f commit 23e28eca11bf3473f6d138c43455d95d698ed015 @javache javache committed with Facebook Github Bot 1 Jul 18, 2016
Showing with 15 additions and 8 deletions.
  1. +4 −7 React/Base/RCTBatchedBridge.m
  2. +2 −0 React/Base/RCTBridge.h
  3. +9 −1 React/Base/RCTBridge.m
@@ -690,25 +690,22 @@ - (void)logMessage:(NSString *)message level:(NSString *)level
/**
* Public. Can be invoked from any thread.
*/
-- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args
+- (void)enqueueJSCall:(NSString *)module method:(NSString *)method args:(NSArray *)args completion:(dispatch_block_t)completion
{
/**
* AnyThread
*/
-
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTBatchedBridge enqueueJSCall:]", nil);
if (!_valid) {
return;
}
- NSArray<NSString *> *ids = [moduleDotMethod componentsSeparatedByString:@"."];
-
- NSString *module = ids[0];
- NSString *method = ids[1];
-
__weak __typeof(self) weakSelf = self;
[self dispatchBlock:^{
[weakSelf _actuallyInvokeAndProcessModule:module method:method arguments:args ?: @[]];
+ if (completion) {
+ completion();
+ }
} queue:RCTJSThread];
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
@@ -100,6 +100,8 @@ RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
* with the JavaScript code. Safe to call from any thread.
*/
- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args;
+- (void)enqueueJSCall:(NSString *)module method:(NSString *)method args:(NSArray *)args completion:(dispatch_block_t)completion;
+
/**
* Retrieve a bridge module instance by name or class. Note that modules are
@@ -276,7 +276,15 @@ - (void)invalidate
- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args
{
- [self.batchedBridge enqueueJSCall:moduleDotMethod args:args];
+ NSArray<NSString *> *ids = [moduleDotMethod componentsSeparatedByString:@"."];
+ NSString *module = ids[0];
+ NSString *method = ids[1];
+ [self enqueueJSCall:module method:method args:args completion:NULL];
+}
+
+- (void)enqueueJSCall:(NSString *)module method:(NSString *)method args:(NSArray *)args completion:(dispatch_block_t)completion
+{
+ [self.batchedBridge enqueueJSCall:module method:method args:args completion:completion];
}
- (void)enqueueCallback:(NSNumber *)cbID args:(NSArray *)args

0 comments on commit 23e28ec

Please sign in to comment.