1// Copyright 2016-present 650 Industries. All rights reserved.
2
3#import <ExpoModulesCore/EXAppDefines.h>
4#import <React/RCTDefines.h>
5
6@implementation EXAppDefines
7
8static NSDictionary *_storage;
9static BOOL _loaded = NO;
10
11+ (BOOL)APP_DEBUG
12{
13  [self throwIfNotLoaded];
14  return [_storage[@"APP_DEBUG"] boolValue];
15}
16
17+ (BOOL)APP_RCT_DEBUG
18{
19  [self throwIfNotLoaded];
20  return [_storage[@"APP_RCT_DEBUG"] boolValue];
21}
22
23+ (BOOL)APP_RCT_DEV
24{
25  [self throwIfNotLoaded];
26  return [_storage[@"APP_RCT_DEV"] boolValue];
27}
28
29+ (BOOL)APP_NEW_ARCH_ENABLED
30{
31  [self throwIfNotLoaded];
32  return [_storage[@"APP_NEW_ARCH_ENABLED"] boolValue];
33}
34
35+ (NSDictionary *)getAllDefines
36{
37  return _storage;
38}
39
40+ (void)load:(NSDictionary *)defines
41{
42  NSAssert([NSThread isMainThread], @"This function must be called on main thread");
43  NSAssert(!_loaded, @"EXAppDefines is already loaded");
44  if (!_loaded) {
45    _storage = defines;
46    _loaded = YES;
47  }
48}
49
50// Private function for EXAppDefinesTest to unload the current state.
51+ (void)_unload
52{
53  _storage = nil;
54  _loaded = NO;
55}
56
57+ (void)throwIfNotLoaded
58{
59  if (!_loaded) {
60    @throw [NSException exceptionWithName:NSInternalInconsistencyException
61                                   reason:@"EXAppDefines is not loaded."
62                                 userInfo:nil];
63  }
64}
65
66
67@end
68