Procházet zdrojové kódy

removed the singleton

Daniel Zlotin před 8 roky
rodič
revize
bc08ea4c8b
5 změnil soubory, kde provedl 15 přidání a 42 odebrání
  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 Zobrazit soubor

@@ -2,17 +2,9 @@
2 2
 #import <Foundation/Foundation.h>
3 3
 #import <UIKit/UIKit.h>
4 4
 
5
-#import "RNNEventEmitter.h"
6
-#import <React/RCTBridge.h>
7
-#import "RNNStore.h"
8
-
9 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 9
 -(void)bootstrap:(NSURL*)jsCodeLocation launchOptions:(NSDictionary*)launchOptions;
18 10
 

+ 12
- 18
ios/RNN.m Zobrazit soubor

@@ -1,43 +1,37 @@
1 1
 
2 2
 #import "RNN.h"
3
-#import "RNNEventEmitter.h"
4
-
5 3
 #import <React/RCTBridge.h>
6
-#import "RNNSplashScreen.h"
7 4
 
5
+#import "RNNEventEmitter.h"
6
+#import "RNNSplashScreen.h"
8 7
 #import "RNNBridgeModule.h"
9 8
 #import "RNNReactRootViewCreator.h"
10 9
 
11 10
 @interface RNN() <RCTBridgeDelegate>
12 11
 
13 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 17
 @end
20 18
 
21 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 23
 	static dispatch_once_t onceToken = 0;
31 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 36
 -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
43 37
 	self.jsCodeLocation = jsCodeLocation;
@@ -63,7 +57,7 @@
63 57
 -(NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge {
64 58
 	
65 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 62
 	RNNBridgeModule* bridgeModule = [[RNNBridgeModule alloc] initWithCommandsHandler:commandsHandler];
69 63
 	return @[bridgeModule];

+ 1
- 9
ios/RNNReactRootViewCreator.m Zobrazit soubor

@@ -1,10 +1,3 @@
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 2
 #import "RNNReactRootViewCreator.h"
10 3
 #import "RNN.h"
@@ -12,8 +5,7 @@
12 5
 
13 6
 @implementation RNNReactRootViewCreator
14 7
 
15
- - (UIView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId
16
-{
8
+- (UIView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId{
17 9
 	if (!rootViewId) {
18 10
 		@throw [NSException exceptionWithName:@"MissingViewId" reason:@"Missing view id" userInfo:nil];
19 11
 	}

+ 0
- 4
ios/RNNStore.m Zobrazit soubor

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

+ 1
- 2
ios/ReactNativeNavigation.m Zobrazit soubor

@@ -1,6 +1,5 @@
1 1
 
2 2
 #import "ReactNativeNavigation.h"
3
-
4 3
 #import "RNN.h"
5 4
 
6 5
 @implementation ReactNativeNavigation
@@ -10,7 +9,7 @@
10 9
 }
11 10
 
12 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 15
 @end