Skip to content

Commit 5c160e5

Browse files
jdthomasfacebook-github-bot
authored andcommittedAug 18, 2018
Way to register RCT_MODULE in Plugin2.0 instead of +load
Summary: [RFC] WIP: Way to register RCT_MODULE in Plugin2.0 instead of +load This seemed like the simplest way to do this to register in the existing didNotFindModule callback so that we don't have to touch any opensource code. NOTE: The new version of this fixes the problems with dylibs, but not the -ObjC flag removal. This seems like the right call to avoid users having to implement c-functions to return their classes; instead we used objc_getClass. Reviewed By: dshahidehpour Differential Revision: D9112719 fbshipit-source-id: cf8df97d7c443cafa0e06a1e61bdf2612944ed87
1 parent c5297c7 commit 5c160e5

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed
 

Diff for: ‎React/Base/RCTBridge+Private.h

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ RCT_EXTERN __attribute__((weak)) void RCTFBQuickPerformanceLoggerConfigureHooks(
2121
RCT_EXTERN void RCTVerifyAllModulesExported(NSArray *extraModules);
2222
#endif
2323

24+
RCT_EXTERN void RCTRegisterModule(Class);
25+
2426
@interface RCTBridge ()
2527

2628
// Private designated initializer

Diff for: ‎React/Base/RCTBridgeModule.h

+10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ RCT_EXTERN void RCTRegisterModule(Class); \
7373
+ (NSString *)moduleName { return @#js_name; } \
7474
+ (void)load { RCTRegisterModule(self); }
7575

76+
/**
77+
* To improve startup performance users may want to generate their module lists
78+
* at build time and hook the delegate to merge with the runtime list. This
79+
* macro takes the place of the above for those cases by omitting the +load
80+
* generation.
81+
*
82+
*/
83+
#define RCT_EXPORT_PRE_REGISTERED_MODULE(js_name) \
84+
+ (NSString *)moduleName { return @#js_name; }
85+
7686
// Implemented by RCT_EXPORT_MODULE
7787
+ (NSString *)moduleName;
7888

Diff for: ‎React/CxxBridge/RCTCxxBridge.mm

+2-4
Original file line numberDiff line numberDiff line change
@@ -650,19 +650,17 @@ - (void)installExtraJSBinding
650650
// Set up moduleData for automatically-exported modules
651651
NSArray<RCTModuleData *> *moduleDataById = [self registerModulesForClasses:modules];
652652

653-
#ifdef RCT_DEBUG
654653
if (lazilyDiscovered) {
654+
#ifdef RCT_DEBUG
655655
// Lazily discovered modules do not require instantiation here,
656656
// as they are not allowed to have pre-instantiated instance
657657
// and must not require the main queue.
658658
for (RCTModuleData *moduleData in moduleDataById) {
659659
RCTAssert(!(moduleData.requiresMainQueueSetup || moduleData.hasInstance),
660660
@"Module \'%@\' requires initialization on the Main Queue or has pre-instantiated, which is not supported for the lazily discovered modules.", moduleData.name);
661661
}
662-
}
663-
else
664662
#endif
665-
{
663+
} else {
666664
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways,
667665
@"-[RCTCxxBridge initModulesWithDispatchGroup:] moduleData.hasInstance", nil);
668666
// Dispatch module init onto main thread for those modules that require it

0 commit comments

Comments
 (0)
Please sign in to comment.