clear realm cache after refreshing simulator

This commit is contained in:
Ari Lazier 2015-11-16 11:26:36 -08:00
parent 53911fefb6
commit f046e4a8ac
1 changed files with 20 additions and 19 deletions

View File

@ -49,8 +49,11 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool cre
} }
#if DEBUG #if DEBUG
#import <GCDWebServers/GCDWebServers.h> #import <GCDWebServers/GCDWebServers.h>
#import <RealmJS/RealmRPC.hpp> #import <RealmJS/RealmRPC.hpp>
#import "shared_realm.hpp"
@interface RealmReact () { @interface RealmReact () {
GCDWebServer *_webServer; GCDWebServer *_webServer;
std::unique_ptr<realm_js::RPCServer> _rpcServer; std::unique_ptr<realm_js::RPCServer> _rpcServer;
@ -149,6 +152,11 @@ static __weak RealmReact *s_currentRealmModule = nil;
#endif #endif
- (void)shutdown { - (void)shutdown {
#if DEBUG
// shutdown rpc if in chrome debug mode
[self shutdownRPC];
#endif
// block until JS thread exits // block until JS thread exits
NSRunLoop *runLoop = _currentJSRunLoop; NSRunLoop *runLoop = _currentJSRunLoop;
if (runLoop) { if (runLoop) {
@ -158,10 +166,7 @@ static __weak RealmReact *s_currentRealmModule = nil;
} }
} }
#if DEBUG realm::Realm::s_global_cache.clear();
// shutdown rpc if in chrome debug mode
[self shutdownRPC];
#endif
} }
- (void)dealloc { - (void)dealloc {
@ -177,25 +182,21 @@ static __weak RealmReact *s_currentRealmModule = nil;
Ivar executorIvar = class_getInstanceVariable([bridge class], "_javaScriptExecutor"); Ivar executorIvar = class_getInstanceVariable([bridge class], "_javaScriptExecutor");
id executor = object_getIvar(bridge, executorIvar); id executor = object_getIvar(bridge, executorIvar);
bool isDebugExecutor = [executor isMemberOfClass:NSClassFromString(@"RCTWebSocketExecutor")]; if ([executor isKindOfClass:NSClassFromString(@"RCTWebSocketExecutor")]) {
#if DEBUG #if DEBUG
if (isDebugExecutor) {
[self startRPC]; [self startRPC];
return; #else
}
#endif
if (isDebugExecutor) {
@throw [NSException exceptionWithName:@"Invalid Executor" reason:@"Chrome debug mode not supported in Release builds" userInfo:nil]; @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 @end