Refactor hot loading implementation on iOS

Reviewed By: milend

Differential Revision: D2795580

fb-gh-sync-id: ad33ba152e40b622b10bfa0122afd6edc28a11bf
This commit is contained in:
Nick Lockwood
2016-01-04 10:39:07 -08:00
committed by facebook-github-bot-9
parent 54f2586735
commit ed4478a4ff
15 changed files with 193 additions and 145 deletions

View File

@@ -23,10 +23,8 @@
#import "RCTPerformanceLogger.h"
#import "RCTUtils.h"
#import "RCTJSCProfiler.h"
#import "RCTBundleURLProcessor.h"
static NSString *const RCTJSCProfilerEnabledDefaultsKey = @"RCTJSCProfilerEnabled";
static NSString *const RCTHotLoadingEnabledDefaultsKey = @"RCTHotLoadingEnabled";
@interface RCTJavaScriptContext : NSObject <RCTInvalidating>
@@ -146,26 +144,6 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
}
}
static BOOL isHotLoadingEnabled()
{
NSString *enabledQS = [[RCTBundleURLProcessor sharedProcessor] getQueryStringValue:@"hot"];
return (enabledQS != nil && [enabledQS isEqualToString:@"true"]) ? YES : NO;
}
static void RCTInstallHotLoading(RCTBridge *bridge, RCTJSCExecutor *executor)
{
[bridge.devMenu addItem:[RCTDevMenuItem toggleItemWithKey:RCTHotLoadingEnabledDefaultsKey title:@"Enable Hot Loading" selectedTitle:@"Disable Hot Loading" handler:^(BOOL enabledOnCurrentBundle) {
[executor executeBlockOnJavaScriptQueue:^{
BOOL enabledOnConfig = isHotLoadingEnabled();
// reload bundle when user change Hot Loading setting
if (enabledOnConfig != enabledOnCurrentBundle) {
[[RCTBundleURLProcessor sharedProcessor] setQueryStringValue:enabledOnCurrentBundle ? @"true" : @"false" forAttribute:@"hot"];
[bridge reload];
}
}];
}]];
}
#endif
+ (void)runRunLoopThread
@@ -320,10 +298,6 @@ static void RCTInstallHotLoading(RCTBridge *bridge, RCTJSCExecutor *executor)
RCTInstallJSCProfiler(_bridge, strongSelf->_context.ctx);
if ([self.bridge.delegate respondsToSelector:@selector(isHotLoadingEnabled)] && [self.bridge.delegate isHotLoadingEnabled]) {
RCTInstallHotLoading(_bridge, strongSelf);
}
for (NSString *event in @[RCTProfileDidStartProfiling, RCTProfileDidEndProfiling]) {
[[NSNotificationCenter defaultCenter] addObserver:strongSelf
selector:@selector(toggleProfilingFlag:)
@@ -535,13 +509,6 @@ static void RCTInstallHotLoading(RCTBridge *bridge, RCTJSCExecutor *executor)
onComplete(error);
}
}), 0, @"js_call", (@{ @"url": sourceURL.absoluteString }))];
#if RCT_DEV
if (isHotLoadingEnabled()) {
// strip initial slash
[_bridge enqueueJSCall:@"HMRClient.enable" args:@[@"ios", [sourceURL.path substringFromIndex: 1]]];
}
#endif
}
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block