From f046e4a8acf2451906545babcccf22b94c7d1c0d Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Mon, 16 Nov 2015 11:26:36 -0800 Subject: [PATCH] clear realm cache after refreshing simulator --- ReactNative/RealmReact.mm | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/ReactNative/RealmReact.mm b/ReactNative/RealmReact.mm index 7d688741..207da3e8 100644 --- a/ReactNative/RealmReact.mm +++ b/ReactNative/RealmReact.mm @@ -49,8 +49,11 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool cre } #if DEBUG + #import #import +#import "shared_realm.hpp" + @interface RealmReact () { GCDWebServer *_webServer; std::unique_ptr _rpcServer; @@ -149,6 +152,11 @@ static __weak RealmReact *s_currentRealmModule = nil; #endif - (void)shutdown { +#if DEBUG + // shutdown rpc if in chrome debug mode + [self shutdownRPC]; +#endif + // block until JS thread exits NSRunLoop *runLoop = _currentJSRunLoop; if (runLoop) { @@ -158,10 +166,7 @@ static __weak RealmReact *s_currentRealmModule = nil; } } -#if DEBUG - // shutdown rpc if in chrome debug mode - [self shutdownRPC]; -#endif + realm::Realm::s_global_cache.clear(); } - (void)dealloc { @@ -177,25 +182,21 @@ static __weak RealmReact *s_currentRealmModule = nil; Ivar executorIvar = class_getInstanceVariable([bridge class], "_javaScriptExecutor"); id executor = object_getIvar(bridge, executorIvar); - bool isDebugExecutor = [executor isMemberOfClass:NSClassFromString(@"RCTWebSocketExecutor")]; - + if ([executor isKindOfClass:NSClassFromString(@"RCTWebSocketExecutor")]) { #if DEBUG - if (isDebugExecutor) { [self startRPC]; - return; - } -#endif - - if (isDebugExecutor) { +#else @throw [NSException exceptionWithName:@"Invalid Executor" reason:@"Chrome debug mode not supported in Release builds" userInfo:nil]; +#endif + } + else { + [executor executeBlockOnJavaScriptQueue:^{ + _currentJSThread = [NSThread currentThread]; + _currentJSRunLoop = [NSRunLoop currentRunLoop]; + JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(executor, true); + RJSInitializeInContext(ctx); + }]; } - - [executor executeBlockOnJavaScriptQueue:^{ - _currentJSThread = [NSThread currentThread]; - _currentJSRunLoop = [NSRunLoop currentRunLoop]; - JSGlobalContextRef ctx = RealmReactGetJSGlobalContextForExecutor(executor, true); - RJSInitializeInContext(ctx); - }]; } @end