[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
#import "RCTAssert.h"
|
|
|
|
#import "RCTBridge.h"
|
|
|
|
#import "RCTConvert.h"
|
|
|
|
#import "RCTContextExecutor.h"
|
|
|
|
#import "RCTFrameUpdate.h"
|
|
|
|
#import "RCTJavaScriptLoader.h"
|
|
|
|
#import "RCTLog.h"
|
|
|
|
#import "RCTModuleData.h"
|
2015-07-27 15:51:28 +00:00
|
|
|
#import "RCTModuleMap.h"
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
#import "RCTModuleMethod.h"
|
|
|
|
#import "RCTPerformanceLogger.h"
|
|
|
|
#import "RCTPerfStats.h"
|
|
|
|
#import "RCTProfile.h"
|
|
|
|
#import "RCTRedBox.h"
|
|
|
|
#import "RCTSourceCode.h"
|
|
|
|
#import "RCTSparseArray.h"
|
|
|
|
#import "RCTUtils.h"
|
|
|
|
|
|
|
|
#define RCTAssertJSThread() \
|
|
|
|
RCTAssert(![NSStringFromClass([_javaScriptExecutor class]) isEqualToString:@"RCTContextExecutor"] || \
|
|
|
|
[[[NSThread currentThread] name] isEqualToString:@"com.facebook.React.JavaScript"], \
|
|
|
|
@"This method must be called on JS thread")
|
|
|
|
|
|
|
|
NSString *const RCTEnqueueNotification = @"RCTEnqueueNotification";
|
|
|
|
NSString *const RCTDequeueNotification = @"RCTDequeueNotification";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Must be kept in sync with `MessageQueue.js`.
|
|
|
|
*/
|
|
|
|
typedef NS_ENUM(NSUInteger, RCTBridgeFields) {
|
|
|
|
RCTBridgeFieldRequestModuleIDs = 0,
|
|
|
|
RCTBridgeFieldMethodIDs,
|
|
|
|
RCTBridgeFieldParamss,
|
|
|
|
};
|
|
|
|
|
|
|
|
RCT_EXTERN NSArray *RCTGetModuleClasses(void);
|
|
|
|
|
|
|
|
static id<RCTJavaScriptExecutor> RCTLatestExecutor = nil;
|
|
|
|
id<RCTJavaScriptExecutor> RCTGetLatestExecutor(void);
|
|
|
|
id<RCTJavaScriptExecutor> RCTGetLatestExecutor(void)
|
|
|
|
{
|
|
|
|
return RCTLatestExecutor;
|
|
|
|
}
|
|
|
|
|
|
|
|
@interface RCTBatchedBridge : RCTBridge
|
|
|
|
|
|
|
|
@property (nonatomic, weak) RCTBridge *parentBridge;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTBatchedBridge
|
|
|
|
{
|
|
|
|
BOOL _loading;
|
2015-08-14 08:59:42 +00:00
|
|
|
BOOL _valid;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
__weak id<RCTJavaScriptExecutor> _javaScriptExecutor;
|
2015-07-27 15:51:28 +00:00
|
|
|
NSMutableArray *_moduleDataByID;
|
|
|
|
RCTModuleMap *_modulesByName;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
CADisplayLink *_mainDisplayLink;
|
|
|
|
CADisplayLink *_jsDisplayLink;
|
|
|
|
NSMutableSet *_frameUpdateObservers;
|
|
|
|
NSMutableArray *_scheduledCalls;
|
|
|
|
RCTSparseArray *_scheduledCallbacks;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithParentBridge:(RCTBridge *)bridge
|
|
|
|
{
|
|
|
|
RCTAssertMainThread();
|
|
|
|
RCTAssertParam(bridge);
|
|
|
|
|
|
|
|
if ((self = [super initWithBundleURL:bridge.bundleURL
|
|
|
|
moduleProvider:bridge.moduleProvider
|
|
|
|
launchOptions:bridge.launchOptions])) {
|
|
|
|
|
|
|
|
_parentBridge = bridge;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Initial State
|
|
|
|
*/
|
|
|
|
_valid = YES;
|
|
|
|
_loading = YES;
|
2015-08-17 14:35:34 +00:00
|
|
|
_moduleDataByID = [NSMutableArray new];
|
|
|
|
_frameUpdateObservers = [NSMutableSet new];
|
|
|
|
_scheduledCalls = [NSMutableArray new];
|
|
|
|
_scheduledCallbacks = [RCTSparseArray new];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
_jsDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(_jsThreadUpdate:)];
|
|
|
|
|
|
|
|
if (RCT_DEV) {
|
|
|
|
_mainDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(_mainThreadUpdate:)];
|
|
|
|
[_mainDisplayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptWillStartLoadingNotification
|
|
|
|
object:self
|
|
|
|
userInfo:@{ @"bridge": self }];
|
2015-07-22 17:54:45 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
[self start];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (void)start
|
|
|
|
{
|
|
|
|
__weak RCTBatchedBridge *weakSelf = self;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
__block NSString *sourceCode;
|
|
|
|
__block NSString *config;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
dispatch_queue_t bridgeQueue = dispatch_queue_create("com.facebook.react.RCTBridgeQueue", DISPATCH_QUEUE_CONCURRENT);
|
|
|
|
dispatch_group_t initModulesAndLoadSource = dispatch_group_create();
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
dispatch_group_enter(initModulesAndLoadSource);
|
|
|
|
[weakSelf loadSource:^(NSError *error, NSString *source) {
|
|
|
|
if (error) {
|
|
|
|
RCTLogError(@"%@", error);
|
|
|
|
} else {
|
|
|
|
sourceCode = source;
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
dispatch_group_leave(initModulesAndLoadSource);
|
|
|
|
}];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
[self initModules];
|
2015-07-28 12:58:01 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
dispatch_group_enter(initModulesAndLoadSource);
|
|
|
|
dispatch_async(bridgeQueue, ^{
|
|
|
|
dispatch_group_t setupJSExecutorAndModuleConfig = dispatch_group_create();
|
|
|
|
dispatch_group_async(setupJSExecutorAndModuleConfig, bridgeQueue, ^{
|
|
|
|
[weakSelf setupExecutor];
|
|
|
|
});
|
2015-07-28 12:58:01 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
dispatch_group_async(setupJSExecutorAndModuleConfig, bridgeQueue, ^{
|
|
|
|
if (weakSelf.isValid) {
|
|
|
|
config = [weakSelf moduleConfig];
|
2015-07-28 22:48:46 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
if (RCTProfileIsProfiling()) {
|
|
|
|
RCTProfileHookModules(weakSelf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch_group_notify(setupJSExecutorAndModuleConfig, bridgeQueue, ^{
|
|
|
|
[weakSelf injectJSONConfiguration:config onComplete:^(__unused NSError *error) {}];
|
|
|
|
|
|
|
|
dispatch_group_leave(initModulesAndLoadSource);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch_group_notify(initModulesAndLoadSource, bridgeQueue, ^{
|
|
|
|
if (sourceCode) {
|
|
|
|
[weakSelf executeSourceCode:sourceCode];
|
|
|
|
}
|
|
|
|
});
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (void)loadSource:(RCTSourceLoadBlock)_onSourceLoad
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
{
|
2015-08-07 13:42:34 +00:00
|
|
|
RCTPerformanceLoggerStart(RCTPLScriptDownload);
|
|
|
|
RCTProfileBeginEvent();
|
|
|
|
|
|
|
|
RCTSourceLoadBlock onSourceLoad = ^(NSError *error, NSString *source) {
|
|
|
|
RCTPerformanceLoggerEnd(RCTPLScriptDownload);
|
|
|
|
RCTProfileEndEvent(@"JavaScript download", @"init,download", @[]);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
NSArray *stack = [error userInfo][@"stack"];
|
|
|
|
if (stack) {
|
|
|
|
[[RCTRedBox sharedInstance] showErrorMessage:[error localizedDescription]
|
|
|
|
withStack:stack];
|
|
|
|
} else {
|
|
|
|
[[RCTRedBox sharedInstance] showErrorMessage:[error localizedDescription]
|
|
|
|
withDetails:[error localizedFailureReason]];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSDictionary *userInfo = @{@"bridge": self, @"error": error};
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidFailToLoadNotification
|
|
|
|
object:_parentBridge
|
|
|
|
userInfo:userInfo];
|
|
|
|
}
|
|
|
|
|
|
|
|
_onSourceLoad(error, source);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ([self.delegate respondsToSelector:@selector(loadSourceForBridge:withBlock:)]) {
|
|
|
|
[self.delegate loadSourceForBridge:_parentBridge withBlock:onSourceLoad];
|
2015-08-08 09:58:30 +00:00
|
|
|
} else if (self.bundleURL) {
|
|
|
|
[RCTJavaScriptLoader loadBundleAtURL:self.bundleURL onComplete:onSourceLoad];
|
2015-08-07 13:42:34 +00:00
|
|
|
} else {
|
|
|
|
// Allow testing without a script
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
_loading = NO;
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidLoadNotification
|
|
|
|
object:_parentBridge
|
|
|
|
userInfo:@{ @"bridge": self }];
|
|
|
|
});
|
|
|
|
onSourceLoad(nil, nil);
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (void)initModules
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
{
|
|
|
|
RCTAssertMainThread();
|
|
|
|
|
|
|
|
// Register passed-in module instances
|
2015-08-17 14:35:34 +00:00
|
|
|
NSMutableDictionary *preregisteredModules = [NSMutableDictionary new];
|
2015-07-28 22:48:46 +00:00
|
|
|
|
|
|
|
NSArray *extraModules = nil;
|
|
|
|
if (self.delegate) {
|
|
|
|
if ([self.delegate respondsToSelector:@selector(extraModulesForBridge:)]) {
|
|
|
|
extraModules = [self.delegate extraModulesForBridge:_parentBridge];
|
|
|
|
}
|
|
|
|
} else if (self.moduleProvider) {
|
|
|
|
extraModules = self.moduleProvider();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (id<RCTBridgeModule> module in extraModules) {
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
preregisteredModules[RCTBridgeModuleNameForClass([module class])] = module;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instantiate modules
|
2015-08-17 14:35:34 +00:00
|
|
|
_moduleDataByID = [NSMutableArray new];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
NSMutableDictionary *modulesByName = [preregisteredModules mutableCopy];
|
|
|
|
for (Class moduleClass in RCTGetModuleClasses()) {
|
|
|
|
NSString *moduleName = RCTBridgeModuleNameForClass(moduleClass);
|
|
|
|
|
|
|
|
// Check if module instance has already been registered for this name
|
|
|
|
id<RCTBridgeModule> module = modulesByName[moduleName];
|
|
|
|
|
|
|
|
if (module) {
|
|
|
|
// Preregistered instances takes precedence, no questions asked
|
|
|
|
if (!preregisteredModules[moduleName]) {
|
|
|
|
// It's OK to have a name collision as long as the second instance is nil
|
2015-08-17 14:35:34 +00:00
|
|
|
RCTAssert([moduleClass new] == nil,
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
@"Attempted to register RCTBridgeModule class %@ for the name "
|
|
|
|
"'%@', but name was already registered by class %@", moduleClass,
|
|
|
|
moduleName, [modulesByName[moduleName] class]);
|
|
|
|
}
|
|
|
|
if ([module class] != moduleClass) {
|
|
|
|
RCTLogInfo(@"RCTBridgeModule of class %@ with name '%@' was encountered "
|
|
|
|
"in the project, but name was already registered by class %@."
|
|
|
|
"That's fine if it's intentional - just letting you know.",
|
|
|
|
moduleClass, moduleName, [modulesByName[moduleName] class]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Module name hasn't been used before, so go ahead and instantiate
|
2015-08-17 14:35:34 +00:00
|
|
|
module = [moduleClass new];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
if (module) {
|
|
|
|
modulesByName[moduleName] = module;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store modules
|
2015-07-27 15:51:28 +00:00
|
|
|
_modulesByName = [[RCTModuleMap alloc] initWithDictionary:modulesByName];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The executor is a bridge module, wait for it to be created and set it before
|
|
|
|
* any other module has access to the bridge
|
|
|
|
*/
|
|
|
|
_javaScriptExecutor = _modulesByName[RCTBridgeModuleNameForClass(self.executorClass)];
|
|
|
|
RCTLatestExecutor = _javaScriptExecutor;
|
|
|
|
|
|
|
|
for (id<RCTBridgeModule> module in _modulesByName.allValues) {
|
2015-08-07 23:07:15 +00:00
|
|
|
|
|
|
|
// Bridge must be set before moduleData is set up, as methodQueue
|
|
|
|
// initialization requires it (View Managers get their queue by calling
|
|
|
|
// self.bridge.uiManager.methodQueue)
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
if ([module respondsToSelector:@selector(setBridge:)]) {
|
|
|
|
module.bridge = self;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTModuleData *moduleData = [[RCTModuleData alloc] initWithExecutor:_javaScriptExecutor
|
2015-08-07 23:07:15 +00:00
|
|
|
moduleID:@(_moduleDataByID.count)
|
|
|
|
instance:module];
|
2015-07-27 15:51:28 +00:00
|
|
|
[_moduleDataByID addObject:moduleData];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
2015-07-01 00:08:28 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTDidCreateNativeModules
|
|
|
|
object:self];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
|
|
|
|
- (void)setupExecutor
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
{
|
2015-08-07 13:42:34 +00:00
|
|
|
[_javaScriptExecutor setUp];
|
|
|
|
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (NSString *)moduleConfig
|
|
|
|
{
|
2015-08-17 14:35:34 +00:00
|
|
|
NSMutableDictionary *config = [NSMutableDictionary new];
|
2015-07-27 15:51:28 +00:00
|
|
|
for (RCTModuleData *moduleData in _moduleDataByID) {
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
config[moduleData.name] = moduleData.config;
|
2015-08-07 13:42:34 +00:00
|
|
|
if ([moduleData.instance conformsToProtocol:@protocol(RCTFrameUpdateObserver)]) {
|
|
|
|
[_frameUpdateObservers addObject:moduleData];
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
2015-08-07 13:42:34 +00:00
|
|
|
|
|
|
|
return RCTJSONStringify(@{
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
@"remoteModuleConfig": config,
|
|
|
|
}, NULL);
|
2015-08-07 13:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)injectJSONConfiguration:(NSString *)configJSON
|
|
|
|
onComplete:(void (^)(NSError *))onComplete
|
|
|
|
{
|
|
|
|
if (!self.isValid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
[_javaScriptExecutor injectJSONText:configJSON
|
2015-07-17 16:05:26 +00:00
|
|
|
asGlobalObjectNamed:@"__fbBatchedBridgeConfig"
|
|
|
|
callback:^(NSError *error) {
|
|
|
|
if (error) {
|
|
|
|
[[RCTRedBox sharedInstance] showError:error];
|
|
|
|
}
|
2015-08-07 13:42:34 +00:00
|
|
|
onComplete(error);
|
2015-07-17 16:05:26 +00:00
|
|
|
}];
|
2015-08-07 13:42:34 +00:00
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (void)executeSourceCode:(NSString *)sourceCode
|
|
|
|
{
|
|
|
|
_loading = NO;
|
|
|
|
|
|
|
|
if (!self.isValid || !_javaScriptExecutor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTSourceCode *sourceCodeModule = self.modules[RCTBridgeModuleNameForClass([RCTSourceCode class])];
|
2015-08-08 09:58:30 +00:00
|
|
|
sourceCodeModule.scriptURL = self.bundleURL;
|
2015-08-07 13:42:34 +00:00
|
|
|
sourceCodeModule.scriptText = sourceCode;
|
|
|
|
|
|
|
|
static BOOL shouldDismiss = NO;
|
|
|
|
if (shouldDismiss) {
|
|
|
|
[[RCTRedBox sharedInstance] dismiss];
|
|
|
|
}
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
shouldDismiss = YES;
|
|
|
|
});
|
|
|
|
|
2015-08-08 09:58:30 +00:00
|
|
|
[self enqueueApplicationScript:sourceCode url:self.bundleURL onComplete:^(NSError *loadError) {
|
2015-08-07 13:42:34 +00:00
|
|
|
|
|
|
|
if (loadError) {
|
|
|
|
[[RCTRedBox sharedInstance] showError:loadError];
|
|
|
|
return;
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
|
|
|
/**
|
2015-08-07 13:42:34 +00:00
|
|
|
* Register the display link to start sending js calls after everything
|
|
|
|
* is setup
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
*/
|
2015-08-07 13:42:34 +00:00
|
|
|
NSRunLoop *targetRunLoop = [_javaScriptExecutor isKindOfClass:[RCTContextExecutor class]] ? [NSRunLoop currentRunLoop] : [NSRunLoop mainRunLoop];
|
|
|
|
[_jsDisplayLink addToRunLoop:targetRunLoop forMode:NSRunLoopCommonModes];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidLoadNotification
|
|
|
|
object:_parentBridge
|
2015-07-28 18:07:45 +00:00
|
|
|
userInfo:@{ @"bridge": self }];
|
2015-08-07 13:42:34 +00:00
|
|
|
}];
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
RCT_NOT_IMPLEMENTED(-initWithBundleURL:(__unused NSURL *)bundleURL
|
|
|
|
moduleProvider:(__unused RCTBridgeModuleProviderBlock)block
|
|
|
|
launchOptions:(__unused NSDictionary *)launchOptions)
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
/**
|
|
|
|
* Prevent super from calling setUp (that'd create another batchedBridge)
|
|
|
|
*/
|
|
|
|
- (void)setUp {}
|
|
|
|
- (void)bindKeys {}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (void)reload
|
|
|
|
{
|
|
|
|
[_parentBridge reload];
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (Class)executorClass
|
|
|
|
{
|
|
|
|
return _parentBridge.executorClass ?: [RCTContextExecutor class];
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (void)setExecutorClass:(Class)executorClass
|
|
|
|
{
|
|
|
|
RCTAssertMainThread();
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
_parentBridge.executorClass = executorClass;
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (NSURL *)bundleURL
|
|
|
|
{
|
|
|
|
return _parentBridge.bundleURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBundleURL:(NSURL *)bundleURL
|
|
|
|
{
|
|
|
|
_parentBridge.bundleURL = bundleURL;
|
|
|
|
}
|
2015-07-14 23:11:42 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (id<RCTBridgeDelegate>)delegate
|
|
|
|
{
|
|
|
|
return _parentBridge.delegate;
|
|
|
|
}
|
2015-07-14 23:11:42 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (BOOL)isLoading
|
|
|
|
{
|
|
|
|
return _loading;
|
|
|
|
}
|
2015-07-28 22:48:46 +00:00
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
- (BOOL)isValid
|
|
|
|
{
|
|
|
|
return _valid;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *)modules
|
|
|
|
{
|
|
|
|
RCTAssert(!self.isValid || _modulesByName != nil, @"Bridge modules have not yet been initialized. "
|
|
|
|
"You may be trying to access a module too early in the startup procedure.");
|
|
|
|
|
|
|
|
return _modulesByName;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - RCTInvalidating
|
|
|
|
|
|
|
|
- (void)invalidate
|
|
|
|
{
|
|
|
|
if (!self.isValid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTAssertMainThread();
|
|
|
|
|
|
|
|
_valid = NO;
|
|
|
|
if (RCTLatestExecutor == _javaScriptExecutor) {
|
|
|
|
RCTLatestExecutor = nil;
|
|
|
|
}
|
|
|
|
|
2015-07-20 09:34:11 +00:00
|
|
|
[_mainDisplayLink invalidate];
|
|
|
|
_mainDisplayLink = nil;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-07-20 09:34:11 +00:00
|
|
|
// Invalidate modules
|
|
|
|
dispatch_group_t group = dispatch_group_create();
|
2015-07-27 15:51:28 +00:00
|
|
|
for (RCTModuleData *moduleData in _moduleDataByID) {
|
2015-07-20 09:34:11 +00:00
|
|
|
if (moduleData.instance == _javaScriptExecutor) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-08 07:28:54 +00:00
|
|
|
|
2015-07-20 09:34:11 +00:00
|
|
|
if ([moduleData.instance respondsToSelector:@selector(invalidate)]) {
|
|
|
|
[moduleData dispatchBlock:^{
|
|
|
|
[(id<RCTInvalidating>)moduleData.instance invalidate];
|
|
|
|
} dispatchGroup:group];
|
|
|
|
}
|
|
|
|
moduleData.queue = nil;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
2015-07-22 17:54:45 +00:00
|
|
|
|
2015-07-20 09:34:11 +00:00
|
|
|
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
|
|
|
[_javaScriptExecutor executeBlockOnJavaScriptQueue:^{
|
|
|
|
[_jsDisplayLink invalidate];
|
|
|
|
_jsDisplayLink = nil;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-07-20 09:34:11 +00:00
|
|
|
[_javaScriptExecutor invalidate];
|
|
|
|
_javaScriptExecutor = nil;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-07-22 17:54:45 +00:00
|
|
|
if (RCTProfileIsProfiling()) {
|
|
|
|
RCTProfileUnhookModules(self);
|
|
|
|
}
|
2015-07-27 15:51:28 +00:00
|
|
|
_moduleDataByID = nil;
|
2015-07-22 17:54:45 +00:00
|
|
|
_modulesByName = nil;
|
|
|
|
_frameUpdateObservers = nil;
|
|
|
|
|
|
|
|
}];
|
2015-07-20 09:34:11 +00:00
|
|
|
});
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - RCTBridge methods
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public. Can be invoked from any thread.
|
|
|
|
*/
|
|
|
|
- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args
|
|
|
|
{
|
|
|
|
NSArray *ids = [moduleDotMethod componentsSeparatedByString:@"."];
|
|
|
|
|
|
|
|
[self _invokeAndProcessModule:@"BatchedBridge"
|
|
|
|
method:@"callFunctionReturnFlushedQueue"
|
2015-07-14 23:16:21 +00:00
|
|
|
arguments:@[ids[0], ids[1], args ?: @[]]];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private hack to support `setTimeout(fn, 0)`
|
|
|
|
*/
|
|
|
|
- (void)_immediatelyCallTimer:(NSNumber *)timer
|
|
|
|
{
|
|
|
|
RCTAssertJSThread();
|
|
|
|
|
|
|
|
dispatch_block_t block = ^{
|
|
|
|
[self _actuallyInvokeAndProcessModule:@"BatchedBridge"
|
|
|
|
method:@"callFunctionReturnFlushedQueue"
|
2015-07-14 23:16:21 +00:00
|
|
|
arguments:@[@"JSTimersExecution", @"callTimers", @[@[timer]]]];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if ([_javaScriptExecutor respondsToSelector:@selector(executeAsyncBlockOnJavaScriptQueue:)]) {
|
|
|
|
[_javaScriptExecutor executeAsyncBlockOnJavaScriptQueue:block];
|
|
|
|
} else {
|
|
|
|
[_javaScriptExecutor executeBlockOnJavaScriptQueue:block];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)enqueueApplicationScript:(NSString *)script url:(NSURL *)url onComplete:(RCTJavaScriptCompleteBlock)onComplete
|
|
|
|
{
|
|
|
|
RCTAssert(onComplete != nil, @"onComplete block passed in should be non-nil");
|
|
|
|
|
|
|
|
RCTProfileBeginFlowEvent();
|
|
|
|
[_javaScriptExecutor executeApplicationScript:script sourceURL:url onComplete:^(NSError *scriptLoadError) {
|
|
|
|
RCTProfileEndFlowEvent();
|
|
|
|
RCTAssertJSThread();
|
|
|
|
|
|
|
|
if (scriptLoadError) {
|
|
|
|
onComplete(scriptLoadError);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTProfileBeginEvent();
|
|
|
|
[_javaScriptExecutor executeJSCall:@"BatchedBridge"
|
|
|
|
method:@"flushedQueue"
|
|
|
|
arguments:@[]
|
|
|
|
callback:^(id json, NSError *error) {
|
|
|
|
RCTProfileEndEvent(@"FetchApplicationScriptCallbacks", @"js_call,init", @{
|
|
|
|
@"json": RCTNullIfNil(json),
|
|
|
|
@"error": RCTNullIfNil(error),
|
|
|
|
});
|
|
|
|
|
2015-07-14 23:16:21 +00:00
|
|
|
[self _handleBuffer:json];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
|
|
|
onComplete(error);
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Payload Generation
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by enqueueJSCall from any thread, or from _immediatelyCallTimer,
|
|
|
|
* on the JS thread, but only in non-batched mode.
|
|
|
|
*/
|
2015-07-14 23:16:21 +00:00
|
|
|
- (void)_invokeAndProcessModule:(NSString *)module method:(NSString *)method arguments:(NSArray *)args
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* AnyThread
|
|
|
|
*/
|
|
|
|
|
|
|
|
RCTProfileBeginFlowEvent();
|
|
|
|
|
|
|
|
__weak RCTBatchedBridge *weakSelf = self;
|
|
|
|
[_javaScriptExecutor executeBlockOnJavaScriptQueue:^{
|
|
|
|
RCTProfileEndFlowEvent();
|
|
|
|
RCTProfileBeginEvent();
|
|
|
|
|
|
|
|
RCTBatchedBridge *strongSelf = weakSelf;
|
|
|
|
if (!strongSelf.isValid || !strongSelf->_scheduledCallbacks || !strongSelf->_scheduledCalls) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RCT_IF_DEV(NSNumber *callID = _RCTProfileBeginFlowEvent();)
|
|
|
|
id call = @{
|
|
|
|
@"js_args": @{
|
|
|
|
@"module": module,
|
|
|
|
@"method": method,
|
|
|
|
@"args": args,
|
|
|
|
},
|
|
|
|
RCT_IF_DEV(@"call_id": callID,)
|
|
|
|
};
|
|
|
|
if ([method isEqualToString:@"invokeCallbackAndReturnFlushedQueue"]) {
|
|
|
|
strongSelf->_scheduledCallbacks[args[0]] = call;
|
|
|
|
} else {
|
|
|
|
[strongSelf->_scheduledCalls addObject:call];
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTProfileEndEvent(@"enqueue_call", @"objc_call", call);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2015-07-14 23:16:21 +00:00
|
|
|
- (void)_actuallyInvokeAndProcessModule:(NSString *)module method:(NSString *)method arguments:(NSArray *)args
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
{
|
|
|
|
RCTAssertJSThread();
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTEnqueueNotification object:nil userInfo:nil];
|
|
|
|
|
2015-07-14 23:11:42 +00:00
|
|
|
RCTJavaScriptCallback processResponse = ^(id json, NSError *error) {
|
|
|
|
if (error) {
|
|
|
|
[[RCTRedBox sharedInstance] showError:error];
|
|
|
|
}
|
|
|
|
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
if (!self.isValid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTDequeueNotification object:nil userInfo:nil];
|
2015-07-14 23:16:21 +00:00
|
|
|
[self _handleBuffer:json];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
[_javaScriptExecutor executeJSCall:module
|
|
|
|
method:method
|
|
|
|
arguments:args
|
|
|
|
callback:processResponse];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Payload Processing
|
|
|
|
|
2015-07-14 23:16:21 +00:00
|
|
|
- (void)_handleBuffer:(id)buffer
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
{
|
|
|
|
RCTAssertJSThread();
|
|
|
|
|
|
|
|
if (buffer == nil || buffer == (id)kCFNull) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray *requestsArray = [RCTConvert NSArray:buffer];
|
|
|
|
|
|
|
|
#if RCT_DEBUG
|
|
|
|
|
|
|
|
if (![buffer isKindOfClass:[NSArray class]]) {
|
|
|
|
RCTLogError(@"Buffer must be an instance of NSArray, got %@", NSStringFromClass([buffer class]));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (NSUInteger fieldIndex = RCTBridgeFieldRequestModuleIDs; fieldIndex <= RCTBridgeFieldParamss; fieldIndex++) {
|
|
|
|
id field = [requestsArray objectAtIndex:fieldIndex];
|
|
|
|
if (![field isKindOfClass:[NSArray class]]) {
|
|
|
|
RCTLogError(@"Field at index %zd in buffer must be an instance of NSArray, got %@", fieldIndex, NSStringFromClass([field class]));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NSArray *moduleIDs = requestsArray[RCTBridgeFieldRequestModuleIDs];
|
|
|
|
NSArray *methodIDs = requestsArray[RCTBridgeFieldMethodIDs];
|
|
|
|
NSArray *paramsArrays = requestsArray[RCTBridgeFieldParamss];
|
|
|
|
|
|
|
|
NSUInteger numRequests = [moduleIDs count];
|
|
|
|
|
|
|
|
if (RCT_DEBUG && (numRequests != methodIDs.count || numRequests != paramsArrays.count)) {
|
|
|
|
RCTLogError(@"Invalid data message - all must be length: %zd", numRequests);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-27 15:51:28 +00:00
|
|
|
NSMapTable *buckets = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsStrongMemory
|
|
|
|
valueOptions:NSPointerFunctionsStrongMemory
|
|
|
|
capacity:_moduleDataByID.count];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
for (NSUInteger i = 0; i < numRequests; i++) {
|
2015-07-27 15:51:28 +00:00
|
|
|
RCTModuleData *moduleData = _moduleDataByID[[moduleIDs[i] integerValue]];
|
|
|
|
if (RCT_DEBUG) {
|
|
|
|
// verify that class has been registered
|
|
|
|
(void)_modulesByName[moduleData.name];
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
NSMutableOrderedSet *set = [buckets objectForKey:moduleData];
|
|
|
|
if (!set) {
|
2015-08-17 14:35:34 +00:00
|
|
|
set = [NSMutableOrderedSet new];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
[buckets setObject:set forKey:moduleData];
|
|
|
|
}
|
|
|
|
[set addObject:@(i)];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (RCTModuleData *moduleData in buckets) {
|
|
|
|
RCTProfileBeginFlowEvent();
|
|
|
|
|
|
|
|
[moduleData dispatchBlock:^{
|
|
|
|
RCTProfileEndFlowEvent();
|
|
|
|
RCTProfileBeginEvent();
|
|
|
|
|
|
|
|
NSOrderedSet *calls = [buckets objectForKey:moduleData];
|
|
|
|
@autoreleasepool {
|
|
|
|
for (NSNumber *indexObj in calls) {
|
|
|
|
NSUInteger index = indexObj.unsignedIntegerValue;
|
|
|
|
[self _handleRequestNumber:index
|
|
|
|
moduleID:[moduleIDs[index] integerValue]
|
|
|
|
methodID:[methodIDs[index] integerValue]
|
2015-07-14 23:16:21 +00:00
|
|
|
params:paramsArrays[index]];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-27 15:51:28 +00:00
|
|
|
|
|
|
|
RCTProfileEndEvent(RCTCurrentThreadName(), @"objc_call,dispatch_async", @{ @"calls": @(calls.count) });
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: batchDidComplete is only used by RCTUIManager - can we eliminate this special case?
|
2015-07-27 15:51:28 +00:00
|
|
|
for (RCTModuleData *moduleData in _moduleDataByID) {
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
if ([moduleData.instance respondsToSelector:@selector(batchDidComplete)]) {
|
|
|
|
[moduleData dispatchBlock:^{
|
|
|
|
[moduleData.instance batchDidComplete];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)_handleRequestNumber:(NSUInteger)i
|
|
|
|
moduleID:(NSUInteger)moduleID
|
|
|
|
methodID:(NSUInteger)methodID
|
|
|
|
params:(NSArray *)params
|
|
|
|
{
|
|
|
|
if (!self.isValid) {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RCT_DEBUG && ![params isKindOfClass:[NSArray class]]) {
|
|
|
|
RCTLogError(@"Invalid module/method/params tuple for request #%zd", i);
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTProfileBeginEvent();
|
|
|
|
|
2015-07-27 15:51:28 +00:00
|
|
|
RCTModuleData *moduleData = _moduleDataByID[moduleID];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
if (RCT_DEBUG && !moduleData) {
|
|
|
|
RCTLogError(@"No module found for id '%zd'", moduleID);
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTModuleMethod *method = moduleData.methods[methodID];
|
|
|
|
if (RCT_DEBUG && !method) {
|
|
|
|
RCTLogError(@"Unknown methodID: %zd for module: %zd (%@)", methodID, moduleID, moduleData.name);
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
@try {
|
2015-07-14 23:16:21 +00:00
|
|
|
[method invokeWithBridge:self module:moduleData.instance arguments:params];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
@catch (NSException *exception) {
|
|
|
|
RCTLogError(@"Exception thrown while invoking %@ on target %@ with params %@: %@", method.JSMethodName, moduleData.name, params, exception);
|
|
|
|
if (!RCT_DEBUG && [exception.name rangeOfString:@"Unhandled JS Exception"].location != NSNotFound) {
|
|
|
|
@throw exception;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTProfileEndEvent(@"Invoke callback", @"objc_call", @{
|
2015-07-28 20:09:22 +00:00
|
|
|
@"module": NSStringFromClass(method.moduleClass),
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
@"method": method.JSMethodName,
|
|
|
|
@"selector": NSStringFromSelector(method.selector),
|
|
|
|
@"args": RCTJSONStringify(RCTNullIfNil(params), NULL),
|
|
|
|
});
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_jsThreadUpdate:(CADisplayLink *)displayLink
|
|
|
|
{
|
|
|
|
RCTAssertJSThread();
|
|
|
|
RCTProfileBeginEvent();
|
|
|
|
|
|
|
|
RCTFrameUpdate *frameUpdate = [[RCTFrameUpdate alloc] initWithDisplayLink:displayLink];
|
|
|
|
for (RCTModuleData *moduleData in _frameUpdateObservers) {
|
|
|
|
id<RCTFrameUpdateObserver> observer = (id<RCTFrameUpdateObserver>)moduleData.instance;
|
|
|
|
if (![observer respondsToSelector:@selector(isPaused)] || ![observer isPaused]) {
|
|
|
|
RCT_IF_DEV(NSString *name = [NSString stringWithFormat:@"[%@ didUpdateFrame:%f]", observer, displayLink.timestamp];)
|
|
|
|
RCTProfileBeginFlowEvent();
|
|
|
|
|
|
|
|
[moduleData dispatchBlock:^{
|
|
|
|
RCTProfileEndFlowEvent();
|
|
|
|
RCTProfileBeginEvent();
|
|
|
|
[observer didUpdateFrame:frameUpdate];
|
|
|
|
RCTProfileEndEvent(name, @"objc_call,fps", nil);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray *calls = [_scheduledCallbacks.allObjects arrayByAddingObjectsFromArray:_scheduledCalls];
|
|
|
|
|
|
|
|
RCT_IF_DEV(
|
|
|
|
RCTProfileImmediateEvent(@"JS Thread Tick", displayLink.timestamp, @"g");
|
|
|
|
|
|
|
|
for (NSDictionary *call in calls) {
|
|
|
|
_RCTProfileEndFlowEvent(call[@"call_id"]);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if (calls.count > 0) {
|
2015-08-17 14:35:34 +00:00
|
|
|
_scheduledCalls = [NSMutableArray new];
|
|
|
|
_scheduledCallbacks = [RCTSparseArray new];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
[self _actuallyInvokeAndProcessModule:@"BatchedBridge"
|
|
|
|
method:@"processBatch"
|
2015-07-14 23:16:21 +00:00
|
|
|
arguments:@[[calls valueForKey:@"js_args"]]];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RCTProfileEndEvent(@"DispatchFrameUpdate", @"objc_call", nil);
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2015-06-29 12:47:21 +00:00
|
|
|
[self.perfStats.jsGraph onTick:displayLink.timestamp];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_mainThreadUpdate:(CADisplayLink *)displayLink
|
|
|
|
{
|
|
|
|
RCTAssertMainThread();
|
|
|
|
|
|
|
|
RCTProfileImmediateEvent(@"VSYNC", displayLink.timestamp, @"g");
|
|
|
|
|
2015-08-07 13:42:34 +00:00
|
|
|
_modulesByName == nil ?: [self.perfStats.uiGraph onTick:displayLink.timestamp];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)startProfiling
|
|
|
|
{
|
|
|
|
RCTAssertMainThread();
|
|
|
|
|
2015-08-08 09:58:30 +00:00
|
|
|
if (![self.bundleURL.scheme isEqualToString:@"http"]) {
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
RCTLogError(@"To run the profiler you must be running from the dev server");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[_javaScriptExecutor executeBlockOnJavaScriptQueue:^{
|
|
|
|
RCTProfileInit(self);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)stopProfiling
|
|
|
|
{
|
|
|
|
RCTAssertMainThread();
|
|
|
|
|
|
|
|
[_javaScriptExecutor executeBlockOnJavaScriptQueue:^{
|
|
|
|
NSString *log = RCTProfileEnd(self);
|
2015-08-08 09:58:30 +00:00
|
|
|
NSString *URLString = [NSString stringWithFormat:@"%@://%@:%@/profile", self.bundleURL.scheme, self.bundleURL.host, self.bundleURL.port];
|
2015-08-07 13:42:34 +00:00
|
|
|
NSURL *URL = [NSURL URLWithString:URLString];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
NSMutableURLRequest *URLRequest = [NSMutableURLRequest requestWithURL:URL];
|
|
|
|
URLRequest.HTTPMethod = @"POST";
|
|
|
|
[URLRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
|
|
|
NSURLSessionTask *task =
|
|
|
|
[[NSURLSession sharedSession] uploadTaskWithRequest:URLRequest
|
|
|
|
fromData:[log dataUsingEncoding:NSUTF8StringEncoding]
|
|
|
|
completionHandler:
|
|
|
|
^(__unused NSData *data, __unused NSURLResponse *response, NSError *error) {
|
|
|
|
if (error) {
|
|
|
|
RCTLogError(@"%@", error.localizedDescription);
|
|
|
|
} else {
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[[[UIAlertView alloc] initWithTitle:@"Profile"
|
|
|
|
message:@"The profile has been generated, check the dev server log for instructions."
|
|
|
|
delegate:nil
|
|
|
|
cancelButtonTitle:@"OK"
|
|
|
|
otherButtonTitles:nil] show];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
[task resume];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|