Skip to content

Commit

Permalink
Adopt new split segments registration approach on iOS
Browse files Browse the repository at this point in the history
Differential Revision: D6284479

fbshipit-source-id: d0d7e8c6a6ce4ecab63739149be69f25df7fbe6f
  • Loading branch information
fromcelticpark authored and facebook-github-bot committed Nov 9, 2017
1 parent cff0d8e commit 6812789
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
7 changes: 7 additions & 0 deletions React/Base/RCTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions React/Base/RCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions React/Base/RCTBridgeDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 8 additions & 6 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -1214,6 +1209,13 @@ - (JSValue *)callFunctionOnModule:(NSString *)module
return ret;
}

- (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path
{
if (_reactInstance) {
_reactInstance->registerBundle(static_cast<uint32_t>(segmentId), path.UTF8String);
}
}

#pragma mark - Payload Processing

- (void)partialBatchDidFlush
Expand Down

0 comments on commit 6812789

Please sign in to comment.