From 681278947eb4039a1d7a65f1edfeef25ae055a4f Mon Sep 17 00:00:00 2001 From: Alex Dvornikov Date: Thu, 9 Nov 2017 11:55:39 -0800 Subject: [PATCH] Adopt new split segments registration approach on iOS Differential Revision: D6284479 fbshipit-source-id: d0d7e8c6a6ce4ecab63739149be69f25df7fbe6f --- React/Base/RCTBridge.h | 7 +++++++ React/Base/RCTBridge.m | 5 +++++ React/Base/RCTBridgeDelegate.h | 7 ------- React/CxxBridge/RCTCxxBridge.mm | 14 ++++++++------ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/React/Base/RCTBridge.h b/React/Base/RCTBridge.h index 450a0d0e38a104..99ad085225f25a 100644 --- a/React/Base/RCTBridge.h +++ b/React/Base/RCTBridge.h @@ -138,6 +138,13 @@ RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass); arguments:(NSArray *)arguments error:(NSError **)error; +/** + * This method registers the file path of an additional JS segment by its ID. + * + * @experimental + */ +- (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path; + /** * Retrieve a bridge module instance by name or class. Note that modules are * lazily instantiated, so calling these methods for the first time with a given diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index a8cef88c7bf4d9..33d8c977a9ea33 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -398,6 +398,11 @@ - (JSValue *)callFunctionOnModule:(NSString *)module return [self.batchedBridge callFunctionOnModule:module method:method arguments:arguments error:error]; } +- (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path +{ + [self.batchedBridge registerSegmentWithId:segmentId path:path]; +} + @end @implementation RCTBridge (JavaScriptCore) diff --git a/React/Base/RCTBridgeDelegate.h b/React/Base/RCTBridgeDelegate.h index f70a024188bad1..1609544a94ff3c 100644 --- a/React/Base/RCTBridgeDelegate.h +++ b/React/Base/RCTBridgeDelegate.h @@ -94,11 +94,4 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge withBlock:(RCTSourceLoadBlock)loadCallback; -/** - * Specifies the path to folder where additional bundles are located - * - * @experimental - */ -- (NSURL *)jsSegmentsDirectory; - @end diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index b5ce3026b2553a..e87196886cf1d8 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -1148,12 +1148,7 @@ - (void)executeApplicationScript:(NSData *)script [self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad]; [self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize]; if (self->_reactInstance) { - NSString *jsSegmentsDirectory = [self.delegate respondsToSelector:@selector(jsSegmentsDirectory)] - ? [[self.delegate jsSegmentsDirectory].path stringByAppendingString:@"/"] - : nil; - auto registry = jsSegmentsDirectory != nil - ? RAMBundleRegistry::multipleBundlesRegistry(std::move(ramBundle), JSIndexedRAMBundle::buildFactory()) - : RAMBundleRegistry::singleBundleRegistry(std::move(ramBundle)); + auto registry = RAMBundleRegistry::multipleBundlesRegistry(std::move(ramBundle), JSIndexedRAMBundle::buildFactory()); self->_reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr), sourceUrlStr.UTF8String, !async); } @@ -1214,6 +1209,13 @@ - (JSValue *)callFunctionOnModule:(NSString *)module return ret; } +- (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path +{ + if (_reactInstance) { + _reactInstance->registerBundle(static_cast(segmentId), path.UTF8String); + } +} + #pragma mark - Payload Processing - (void)partialBatchDidFlush