Browse Source

removed the singleton

Daniel Zlotin 8 years ago
parent
commit
bc08ea4c8b
5 changed files with 15 additions and 42 deletions
  1. 1
    9
      ios/RNN.h
  2. 12
    18
      ios/RNN.m
  3. 1
    9
      ios/RNNReactRootViewCreator.m
  4. 0
    4
      ios/RNNStore.m
  5. 1
    2
      ios/ReactNativeNavigation.m

+ 1
- 9
ios/RNN.h View File

2
 #import <Foundation/Foundation.h>
2
 #import <Foundation/Foundation.h>
3
 #import <UIKit/UIKit.h>
3
 #import <UIKit/UIKit.h>
4
 
4
 
5
-#import "RNNEventEmitter.h"
6
-#import <React/RCTBridge.h>
7
-#import "RNNStore.h"
8
-
9
 @interface RNN : NSObject
5
 @interface RNN : NSObject
10
 
6
 
11
-@property (readonly) RCTBridge* bridge;
12
-@property (readonly) RNNEventEmitter* eventEmitter;
13
-@property (readonly) RNNStore *store;
14
-
15
-+(instancetype)instance;
7
++(instancetype)sharedInstance;
16
 
8
 
17
 -(void)bootstrap:(NSURL*)jsCodeLocation launchOptions:(NSDictionary*)launchOptions;
9
 -(void)bootstrap:(NSURL*)jsCodeLocation launchOptions:(NSDictionary*)launchOptions;
18
 
10
 

+ 12
- 18
ios/RNN.m View File

1
 
1
 
2
 #import "RNN.h"
2
 #import "RNN.h"
3
-#import "RNNEventEmitter.h"
4
-
5
 #import <React/RCTBridge.h>
3
 #import <React/RCTBridge.h>
6
-#import "RNNSplashScreen.h"
7
 
4
 
5
+#import "RNNEventEmitter.h"
6
+#import "RNNSplashScreen.h"
8
 #import "RNNBridgeModule.h"
7
 #import "RNNBridgeModule.h"
9
 #import "RNNReactRootViewCreator.h"
8
 #import "RNNReactRootViewCreator.h"
10
 
9
 
11
 @interface RNN() <RCTBridgeDelegate>
10
 @interface RNN() <RCTBridgeDelegate>
12
 
11
 
13
 @property NSURL* jsCodeLocation;
12
 @property NSURL* jsCodeLocation;
14
-@property (readwrite) RCTBridge* bridge;
15
-@property (readwrite) RNNEventEmitter* eventEmitter;
16
-
17
-@property (readwrite) RNNStore *store;
13
+@property RCTBridge* bridge;
14
+@property RNNEventEmitter* eventEmitter;
15
+@property RNNStore *store;
18
 
16
 
19
 @end
17
 @end
20
 
18
 
21
 @implementation RNN
19
 @implementation RNN
22
 
20
 
23
-
24
-# pragma mark public
25
-
26
-
27
-+(instancetype)instance
28
-{
29
-	static RNN *sharedInstance = nil;
21
++(instancetype) sharedInstance {
22
+	static RNN *instance = nil;
30
 	static dispatch_once_t onceToken = 0;
23
 	static dispatch_once_t onceToken = 0;
31
 	dispatch_once(&onceToken,^{
24
 	dispatch_once(&onceToken,^{
32
-		if (sharedInstance == nil)
25
+		if (instance == nil)
33
 		{
26
 		{
34
-			sharedInstance = [[RNN alloc] init];
27
+			instance = [[RNN alloc] init];
35
 		}
28
 		}
36
 	});
29
 	});
37
 	
30
 	
38
-	return sharedInstance;
31
+	return instance;
39
 }
32
 }
40
 
33
 
34
+# pragma mark public
41
 
35
 
42
 -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
36
 -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
43
 	self.jsCodeLocation = jsCodeLocation;
37
 	self.jsCodeLocation = jsCodeLocation;
63
 -(NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge {
57
 -(NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge {
64
 	
58
 	
65
 	RNNControllerFactory *controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:self.store];
59
 	RNNControllerFactory *controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:self.store];
66
-	RNNCommandsHandler* commandsHandler = [[RNNCommandsHandler alloc]initWithStore:[RNN instance].store controllerFactory:controllerFactory];
60
+	RNNCommandsHandler* commandsHandler = [[RNNCommandsHandler alloc]initWithStore:self.store controllerFactory:controllerFactory];
67
 	
61
 	
68
 	RNNBridgeModule* bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:commandsHandler];
62
 	RNNBridgeModule* bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:commandsHandler];
69
 	return @[bridgeModule];
63
 	return @[bridgeModule];

+ 1
- 9
ios/RNNReactRootViewCreator.m View File

1
-//
2
-//  RNNReactRootViewCreator.m
3
-//  ReactNativeNavigation
4
-//
5
-//  Created by Ran Greenberg on 08/02/2017.
6
-//  Copyright © 2017 Wix. All rights reserved.
7
-//
8
 
1
 
9
 #import "RNNReactRootViewCreator.h"
2
 #import "RNNReactRootViewCreator.h"
10
 #import "RNN.h"
3
 #import "RNN.h"
12
 
5
 
13
 @implementation RNNReactRootViewCreator
6
 @implementation RNNReactRootViewCreator
14
 
7
 
15
- - (UIView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId
16
-{
8
+- (UIView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId{
17
 	if (!rootViewId) {
9
 	if (!rootViewId) {
18
 		@throw [NSException exceptionWithName:@"MissingViewId" reason:@"Missing view id" userInfo:nil];
10
 		@throw [NSException exceptionWithName:@"MissingViewId" reason:@"Missing view id" userInfo:nil];
19
 	}
11
 	}

+ 0
- 4
ios/RNNStore.m View File

20
 
20
 
21
 -(UIViewController *)findContainerForId:(NSString *)containerId {
21
 -(UIViewController *)findContainerForId:(NSString *)containerId {
22
 	return [self.containerStore objectForKey:containerId];
22
 	return [self.containerStore objectForKey:containerId];
23
-	
24
 }
23
 }
25
 
24
 
26
-
27
 - (void)setContainer:(UIViewController*)viewController containerId:(NSString*)containerId {
25
 - (void)setContainer:(UIViewController*)viewController containerId:(NSString*)containerId {
28
-
29
 	UIViewController *existingVewController = [self findContainerForId:containerId];
26
 	UIViewController *existingVewController = [self findContainerForId:containerId];
30
 	if (existingVewController) {
27
 	if (existingVewController) {
31
 		@throw [NSException exceptionWithName:@"MultipleContainerId" reason:[@"Container id already exists " stringByAppendingString:containerId] userInfo:nil];
28
 		@throw [NSException exceptionWithName:@"MultipleContainerId" reason:[@"Container id already exists " stringByAppendingString:containerId] userInfo:nil];
34
 	[self.containerStore setObject:viewController forKey:containerId];
31
 	[self.containerStore setObject:viewController forKey:containerId];
35
 }
32
 }
36
 
33
 
37
-
38
 - (void)removeContainer:(NSString*)containerId {
34
 - (void)removeContainer:(NSString*)containerId {
39
 	[self.containerStore removeObjectForKey:containerId];
35
 	[self.containerStore removeObjectForKey:containerId];
40
 }
36
 }

+ 1
- 2
ios/ReactNativeNavigation.m View File

1
 
1
 
2
 #import "ReactNativeNavigation.h"
2
 #import "ReactNativeNavigation.h"
3
-
4
 #import "RNN.h"
3
 #import "RNN.h"
5
 
4
 
6
 @implementation ReactNativeNavigation
5
 @implementation ReactNativeNavigation
10
 }
9
 }
11
 
10
 
12
 +(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
11
 +(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
13
-	[[RNN instance] bootstrap:jsCodeLocation launchOptions:launchOptions];
12
+	[[RNN sharedInstance] bootstrap:jsCodeLocation launchOptions:launchOptions];
14
 }
13
 }
15
 
14
 
16
 @end
15
 @end