Use new enqueueJSCall method everywhere

Reviewed By: majak

Differential Revision: D3605263

fbshipit-source-id: 215f896d675b937593c8b796ed6ec5261ac74dbf
This commit is contained in:
Pieter De Baets 2016-08-02 11:06:19 -07:00 committed by Facebook Github Bot 8
parent 1ab4b2a792
commit e762d961cd
8 changed files with 62 additions and 30 deletions

View File

@ -19,7 +19,7 @@
#import "RCTEventDispatcher.h"
#import "RCTBridge+Private.h"
@interface RCTTestEvent : NSObject <RCTEvent>
@interface RCTTestEvent : NSObject <RCTEvent>
@property (atomic, assign, readwrite) BOOL canCoalesce;
@end
@ -54,7 +54,7 @@
+ (NSString *)moduleDotMethod
{
return @"RCTDeviceEventEmitter.emit";
return @"MyCustomEventemitter.emit";
}
- (NSArray *)arguments
@ -100,8 +100,10 @@
- (void)testLegacyEventsAreImmediatelyDispatched
{
[[_bridge expect] enqueueJSCall:_JSMethod
args:[_testEvent arguments]];
[[_bridge expect] enqueueJSCall:@"RCTDeviceEventEmitter"
method:@"emit"
args:[_testEvent arguments]
completion:NULL];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@ -154,9 +156,8 @@
[_eventDispatcher sendEvent:_testEvent];
[_bridge verify];
// eventsEmittingBlock would be called when js is no longer busy, which will result in emitting events
[[_bridge expect] enqueueJSCall:@"RCTDeviceEventEmitter.emit"
[[_bridge expect] enqueueJSCall:[[_testEvent class] moduleDotMethod]
args:[_testEvent arguments]];
eventsEmittingBlock();
[_bridge verify];
@ -174,7 +175,7 @@
eventsEmittingBlock = block;
return YES;
}] queue:RCTJSThread];
[[_bridge expect] enqueueJSCall:@"RCTDeviceEventEmitter.emit"
[[_bridge expect] enqueueJSCall:[[_testEvent class] moduleDotMethod]
args:[_testEvent arguments]];
RCTTestEvent *ignoredEvent = [[RCTTestEvent alloc] initWithViewTag:nil
@ -201,9 +202,9 @@
eventsEmittingBlock = block;
return YES;
}] queue:RCTJSThread];
[[_bridge expect] enqueueJSCall:@"RCTDeviceEventEmitter.emit"
[[_bridge expect] enqueueJSCall:[[_testEvent class] moduleDotMethod]
args:[firstEvent arguments]];
[[_bridge expect] enqueueJSCall:@"RCTDeviceEventEmitter.emit"
[[_bridge expect] enqueueJSCall:[[_testEvent class] moduleDotMethod]
args:[_testEvent arguments]];
@ -231,9 +232,9 @@
eventsEmittingBlock = block;
return YES;
}] queue:RCTJSThread];
[[_bridge expect] enqueueJSCall:@"RCTDeviceEventEmitter.emit"
[[_bridge expect] enqueueJSCall:[[_testEvent class] moduleDotMethod]
args:[firstEvent arguments]];
[[_bridge expect] enqueueJSCall:@"RCTDeviceEventEmitter.emit"
[[_bridge expect] enqueueJSCall:[[_testEvent class] moduleDotMethod]
args:[secondEvent arguments]];

View File

@ -201,6 +201,11 @@ class MessageQueue {
'Module %s is not a registered callable module.',
module
);
invariant(
!!moduleMethods[method],
'Method %s does not exist on module %s',
method, module
);
const result = moduleMethods[method].apply(moduleMethods, args);
Systrace.endEvent();
return result;
@ -219,7 +224,7 @@ class MessageQueue {
let errorMessage = `Callback with id ${cbID}: ${module}.${method}() not found`;
if (method) {
errorMessage = `The callback ${method}() exists in module ${module}, `
+ `but only one callback may be registered to a function in a native module.`;
+ 'but only one callback may be registered to a function in a native module.';
}
invariant(
callback,

View File

@ -557,7 +557,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithDelegate:(id<RCTBridgeDelegate>)dele
NSString *path = [self.bundleURL.path substringFromIndex:1]; // strip initial slash
NSString *host = self.bundleURL.host;
NSNumber *port = self.bundleURL.port;
[self enqueueJSCall:@"HMRClient.enable" args:@[@"ios", path, host, RCTNullIfNil(port)]];
[self enqueueJSCall:@"HMRClient"
method:@"enable"
args:@[@"ios", path, host, RCTNullIfNil(port)]
completion:NULL];
}
#endif
}
@ -745,8 +748,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
- (void)logMessage:(NSString *)message level:(NSString *)level
{
if (RCT_DEBUG && [_javaScriptExecutor isValid]) {
[self enqueueJSCall:@"RCTLog.logIfNoNativeHook"
args:@[level, message]];
[self enqueueJSCall:@"RCTLog"
method:@"logIfNoNativeHook"
args:@[level, message]
completion:NULL];
}
}

View File

@ -63,14 +63,18 @@ RCT_EXPORT_MODULE()
- (void)sendAppEventWithName:(NSString *)name body:(id)body
{
[_bridge enqueueJSCall:@"RCTNativeAppEventEmitter.emit"
args:body ? @[name, body] : @[name]];
[_bridge enqueueJSCall:@"RCTNativeAppEventEmitter"
method:@"emit"
args:body ? @[name, body] : @[name]
completion:NULL];
}
- (void)sendDeviceEventWithName:(NSString *)name body:(id)body
{
[_bridge enqueueJSCall:@"RCTDeviceEventEmitter.emit"
args:body ? @[name, body] : @[name]];
[_bridge enqueueJSCall:@"RCTDeviceEventEmitter"
method:@"emit"
args:body ? @[name, body] : @[name]
completion:NULL];
}
- (void)sendInputEventWithName:(NSString *)name body:(NSDictionary *)body
@ -81,8 +85,10 @@ RCT_EXPORT_MODULE()
}
name = RCTNormalizeInputEventName(name);
[_bridge enqueueJSCall:@"RCTEventEmitter.receiveEvent"
args:body ? @[body[@"target"], name, body] : @[body[@"target"], name]];
[_bridge enqueueJSCall:@"RCTEventEmitter"
method:@"receiveEvent"
args:body ? @[body[@"target"], name, body] : @[body[@"target"], name]
completion:NULL];
}
- (void)sendTextEventWithType:(RCTTextEventType)type

View File

@ -228,8 +228,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
@"initialProps": _appProperties ?: @{},
};
[bridge enqueueJSCall:@"AppRegistry.runApplication"
args:@[moduleName, appParameters]];
[bridge enqueueJSCall:@"AppRegistry"
method:@"runApplication"
args:@[moduleName, appParameters]
completion:NULL];
}
- (void)setSizeFlexibility:(RCTRootViewSizeFlexibility)sizeFlexibility
@ -376,8 +378,10 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder)
if (self.userInteractionEnabled) {
self.userInteractionEnabled = NO;
[(RCTRootView *)self.superview contentViewInvalidated];
[_bridge enqueueJSCall:@"AppRegistry.unmountApplicationComponentAtRootTag"
args:@[self.reactTag]];
[_bridge enqueueJSCall:@"AppRegistry"
method:@"unmountApplicationComponentAtRootTag"
args:@[self.reactTag]
completion:NULL];
}
}

View File

@ -559,7 +559,10 @@ static void installBasicSynchronousHooksOnContext(JSContext *context)
{
[self executeBlockOnJavaScriptQueue:^{
BOOL enabled = [notification.name isEqualToString:RCTProfileDidStartProfiling];
[self->_bridge enqueueJSCall:@"Systrace.setEnabled" args:@[enabled ? @YES : @NO]];
[self->_bridge enqueueJSCall:@"Systrace"
method:@"setEnabled"
args:@[enabled ? @YES : @NO]
completion:NULL];
}];
}

View File

@ -46,8 +46,10 @@
eventName, [self class], [[self supportedEvents] componentsJoinedByString:@"`, `"]);
}
if (_listenerCount > 0) {
[_bridge enqueueJSCall:@"RCTDeviceEventEmitter.emit"
args:body ? @[eventName, body] : @[eventName]];
[_bridge enqueueJSCall:@"RCTDeviceEventEmitter"
method:@"emit"
args:body ? @[eventName, body] : @[eventName]
completion:NULL];
} else {
RCTLogWarn(@"Sending `%@` with no listeners registered.", eventName);
}

View File

@ -192,7 +192,10 @@ RCT_EXPORT_MODULE()
// Call timers that need to be called
if (timersToCall.count > 0) {
[_bridge enqueueJSCall:@"JSTimersExecution.callTimers" args:@[timersToCall]];
[_bridge enqueueJSCall:@"JSTimersExecution"
method:@"callTimers"
args:@[timersToCall]
completion:NULL];
}
if (_sendIdleEvents) {
@ -200,7 +203,10 @@ RCT_EXPORT_MODULE()
if (kFrameDuration - frameElapsed >= kIdleCallbackFrameDeadline) {
NSTimeInterval currentTimestamp = [[NSDate date] timeIntervalSince1970];
NSNumber *absoluteFrameStartMS = @((currentTimestamp - frameElapsed) * 1000);
[_bridge enqueueJSCall:@"JSTimersExecution.callIdleCallbacks" args:@[absoluteFrameStartMS]];
[_bridge enqueueJSCall:@"JSTimersExecution"
method:@"callIdleCallbacks"
args:@[absoluteFrameStartMS]
completion:NULL];
}
}