Don't instantiate all native modules on invalidate

Reviewed By: majak

Differential Revision: D3175599

fb-gh-sync-id: 86b60a8bd757765d35cce6248a613c8167400bd9
fbshipit-source-id: 86b60a8bd757765d35cce6248a613c8167400bd9
This commit is contained in:
Pieter De Baets 2016-04-13 18:26:56 -07:00 committed by Facebook Github Bot 9
parent 0db5439892
commit a8f4159fc7
1 changed files with 11 additions and 4 deletions

View File

@ -590,15 +590,22 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
// Invalidate modules
dispatch_group_t group = dispatch_group_create();
for (RCTModuleData *moduleData in _moduleDataByName.allValues) {
if (moduleData.instance == _javaScriptExecutor) {
for (RCTModuleData *moduleData in _moduleDataByID) {
// Be careful when grabbing an instance here, we don't want to instantiate
// any modules just to invalidate them.
id<RCTBridgeModule> instance = nil;
if ([moduleData hasInstance]) {
instance = moduleData.instance;
}
if (instance == _javaScriptExecutor) {
continue;
}
if ([moduleData.instance respondsToSelector:@selector(invalidate)]) {
if ([instance respondsToSelector:@selector(invalidate)]) {
dispatch_group_enter(group);
[self dispatchBlock:^{
[(id<RCTInvalidating>)moduleData.instance invalidate];
[(id<RCTInvalidating>)instance invalidate];
dispatch_group_leave(group);
} queue:moduleData.methodQueue];
}