123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
-
- #import "RNNStore.h"
- #import "RNNRootViewController.h"
- @interface RNNStore ()
-
- @end
-
- @implementation RNNStore {
- NSMapTable* _componentStore;
- NSMutableArray* _pendingModalIdsToDismiss;
- BOOL _isReadyToReceiveCommands;
- }
-
- -(instancetype)init {
- self = [super init];
- _isReadyToReceiveCommands = false;
- _componentStore = [NSMapTable strongToWeakObjectsMapTable];
- _pendingModalIdsToDismiss = [NSMutableArray new];
- return self;
- }
-
- -(UIViewController *)findComponentForId:(NSString *)componentId {
- return [_componentStore objectForKey:componentId];
- }
-
- - (void)setComponent:(UIViewController*)viewController componentId:(NSString*)componentId {
- UIViewController *existingVewController = [self findComponentForId:componentId];
- if (existingVewController) {
- @throw [NSException exceptionWithName:@"MultipleComponentId" reason:[@"Component id already exists " stringByAppendingString:componentId] userInfo:nil];
- }
-
- [_componentStore setObject:viewController forKey:componentId];
- }
-
- - (void)removeComponent:(NSString*)componentId {
- [_componentStore removeObjectForKey:componentId];
- }
-
- - (void)removeComponentByViewControllerInstance:(UIViewController*)componentInstance {
- NSString *foundKey = [self componentKeyForInstance:componentInstance];
- if (foundKey) {
- [self removeComponent:foundKey];
- }
- }
-
- -(void)setReadyToReceiveCommands:(BOOL)isReady {
- _isReadyToReceiveCommands = isReady;
- }
-
- -(BOOL)isReadyToReceiveCommands {
- return _isReadyToReceiveCommands;
- }
-
- -(NSMutableArray *)pendingModalIdsToDismiss {
- return _pendingModalIdsToDismiss;
- }
-
- -(void)clean {
- _isReadyToReceiveCommands = false;
- [_pendingModalIdsToDismiss removeAllObjects];
- [_componentStore removeAllObjects];
- }
-
- -(NSString*)componentKeyForInstance:(UIViewController*)instance {
- for (NSString *key in _componentStore) {
- UIViewController *value = [_componentStore objectForKey:key];
- if (value == instance) {
- return key;
- }
- }
- return nil;
- }
-
- @end
|