Defer constants gathering until after setup
Reviewed By: javache Differential Revision: D2986095 fb-gh-sync-id: 1f449e69ca74466e7951d621ceaf624abe034139 shipit-source-id: 1f449e69ca74466e7951d621ceaf624abe034139
This commit is contained in:
parent
8d44c2db4f
commit
d7d47d8120
|
@ -342,6 +342,12 @@ RCT_EXTERN NSArray<Class> *RCTGetModuleClasses(void);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (RCTModuleData *moduleData in _moduleDataByID) {
|
||||||
|
if (moduleData.hasInstance) {
|
||||||
|
[moduleData gatherConstants];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,14 @@
|
||||||
*/
|
*/
|
||||||
- (void)finishSetupForInstance;
|
- (void)finishSetupForInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls `constantsToExport` on the module and stores the result. Note that
|
||||||
|
* this will init the module if it has not already been created. This method
|
||||||
|
* can be called on any thread, but may block the main thread briefly if the
|
||||||
|
* module implements `constantsToExport`.
|
||||||
|
*/
|
||||||
|
- (void)gatherConstants;
|
||||||
|
|
||||||
@property (nonatomic, strong, readonly) Class moduleClass;
|
@property (nonatomic, strong, readonly) Class moduleClass;
|
||||||
@property (nonatomic, copy, readonly) NSString *name;
|
@property (nonatomic, copy, readonly) NSString *name;
|
||||||
|
|
||||||
|
|
|
@ -80,11 +80,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTDidInitializeModuleNotification
|
[[NSNotificationCenter defaultCenter] postNotificationName:RCTDidInitializeModuleNotification
|
||||||
object:_bridge
|
object:_bridge
|
||||||
userInfo:@{@"module": _instance}];
|
userInfo:@{@"module": _instance}];
|
||||||
|
|
||||||
if (RCTClassOverridesInstanceMethod(_moduleClass, @selector(constantsToExport))) {
|
|
||||||
RCTAssertMainThread();
|
|
||||||
_constantsToExport = [_instance constantsToExport];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +135,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
|
||||||
[_instanceLock unlock];
|
[_instanceLock unlock];
|
||||||
|
|
||||||
[self finishSetupForInstance];
|
[self finishSetupForInstance];
|
||||||
|
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,10 +179,23 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
|
||||||
return _methods;
|
return _methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)gatherConstants
|
||||||
|
{
|
||||||
|
if (!_constantsToExport) {
|
||||||
|
if (RCTClassOverridesInstanceMethod(_moduleClass, @selector(constantsToExport))) {
|
||||||
|
RCTAssert(_instance, @"constantsToExport called before instance created.");
|
||||||
|
RCTExecuteOnMainThread(^{
|
||||||
|
_constantsToExport = [_instance constantsToExport] ?: @{};
|
||||||
|
}, YES);
|
||||||
|
} else {
|
||||||
|
_constantsToExport = @{};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (NSArray *)config
|
- (NSArray *)config
|
||||||
{
|
{
|
||||||
__block NSDictionary<NSString *, id> *constants = _constantsToExport;
|
__block NSDictionary<NSString *, id> *constants = _constantsToExport;
|
||||||
_constantsToExport = nil; // Not needed any more
|
|
||||||
|
|
||||||
if (constants.count == 0 && self.methods.count == 0) {
|
if (constants.count == 0 && self.methods.count == 0) {
|
||||||
return (id)kCFNull; // Nothing to export
|
return (id)kCFNull; // Nothing to export
|
||||||
|
|
Loading…
Reference in New Issue