Browse Source

refactoring and fixes

Daniel Zlotin 7 years ago
parent
commit
106c303432

+ 20
- 0
integration/SingleScreen.test.js View File

@@ -0,0 +1,20 @@
1
+describe('single screen integration', () => {
2
+  let Navigation;
3
+  let mockNativeNavigation;
4
+
5
+  beforeEach(() => {
6
+    mockNativeNavigation = {};
7
+    require('react-native').NativeModules.NativeNavigation = mockNativeNavigation;
8
+    Navigation = require('../../src/index').default;
9
+  });
10
+
11
+  xit('startApp directs to native with constructed hirarchy for single screens', () => {
12
+    mockNativeNavigation.startApp = jest.fn();
13
+    Navigation.startApp({
14
+      container: {
15
+        key: 'com.integration.MyFirstScreen'
16
+      }
17
+    });
18
+    expect(mockNativeNavigation.startApp).toHaveBeenCalledTimes(1);
19
+  });
20
+});

integration/remx-support.test.js → integration/remx/remx.test.js View File

@@ -7,8 +7,8 @@ describe('remx support', () => {
7 7
   let store;
8 8
 
9 9
   beforeEach(() => {
10
-    MyConnectedContainer = require('./remx-support-component').default;
11
-    store = require('./remx-support-store');
10
+    MyConnectedContainer = require('./remxComponent').default;
11
+    store = require('./remxStore');
12 12
   });
13 13
 
14 14
   it('renders normally', () => {

integration/remx-support-component.js → integration/remx/remxComponent.js View File

@@ -3,7 +3,7 @@ import React, {Component} from 'react';
3 3
 
4 4
 import {connect} from 'remx/react-native';
5 5
 
6
-import {selectors} from './remx-support-store';
6
+import {selectors} from './remxStore';
7 7
 
8 8
 class MyContainer extends Component {
9 9
   constructor(props) {

integration/remx-support-store.js → integration/remx/remxStore.js View File


+ 177
- 0
playground/.gitignore View File

@@ -1,3 +1,174 @@
1
+############
2
+# Node
3
+############
4
+# Logs
5
+logs
6
+*.log
7
+npm-debug.log*
8
+
9
+# Runtime data
10
+pids
11
+*.pid
12
+*.seed
13
+
14
+# Directory for instrumented libs generated by jscoverage/JSCover
15
+lib-cov
16
+
17
+# Coverage directory used by tools like istanbul
18
+coverage
19
+
20
+# nyc test coverage
21
+.nyc_output
22
+
23
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24
+.grunt
25
+
26
+# node-waf configuration
27
+.lock-wscript
28
+
29
+# Compiled binary addons (http://nodejs.org/api/addons.html)
30
+build/Release
31
+
32
+# Dependency directories
33
+node_modules
34
+jspm_packages
35
+
36
+# Optional npm cache directory
37
+.npm
38
+
39
+# Optional REPL history
40
+.node_repl_history
41
+
42
+################
43
+# JetBrains
44
+################
45
+.idea
46
+
47
+## File-based project format:
48
+*.iws
49
+
50
+## Plugin-specific files:
51
+
52
+# IntelliJ
53
+/out/
54
+
55
+# mpeltonen/sbt-idea plugin
56
+.idea_modules/
57
+
58
+# JIRA plugin
59
+atlassian-ide-plugin.xml
60
+
61
+# Crashlytics plugin (for Android Studio and IntelliJ)
62
+com_crashlytics_export_strings.xml
63
+crashlytics.properties
64
+crashlytics-build.properties
65
+fabric.properties
66
+
67
+
68
+############
69
+# iOS
70
+############
71
+# Xcode
72
+#
73
+# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
74
+
75
+## Build generated
76
+ios/build/
77
+ios/DerivedData/
78
+
79
+## Various settings
80
+*.pbxuser
81
+!default.pbxuser
82
+*.mode1v3
83
+!default.mode1v3
84
+*.mode2v3
85
+!default.mode2v3
86
+*.perspectivev3
87
+!default.perspectivev3
88
+ios/xcuserdata/
89
+
90
+## Other
91
+*.moved-aside
92
+*.xcuserstate
93
+
94
+## Obj-C/Swift specific
95
+*.hmap
96
+*.ipa
97
+*.dSYM.zip
98
+*.dSYM
99
+
100
+# CocoaPods
101
+#
102
+# We recommend against adding the Pods directory to your .gitignore. However
103
+# you should judge for yourself, the pros and cons are mentioned at:
104
+# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
105
+#
106
+ios/Pods/
107
+
108
+# Carthage
109
+#
110
+# Add this line if you want to avoid checking in source code from Carthage dependencies.
111
+# Carthage/Checkouts
112
+
113
+Carthage/Build
114
+
115
+# fastlane
116
+#
117
+# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
118
+# screenshots whenever they are needed.
119
+# For more information about the recommended setup visit:
120
+# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
121
+
122
+fastlane/report.xml
123
+fastlane/screenshots
124
+
125
+
126
+############
127
+# Android
128
+############
129
+# Built application files
130
+*.apk
131
+*.ap_
132
+
133
+# Files for the Dalvik VM
134
+*.dex
135
+
136
+# Java class files
137
+*.class
138
+
139
+# Generated files
140
+android/bin/
141
+android/gen/
142
+android/out/
143
+
144
+# Gradle files
145
+android/.gradle/
146
+android/build/
147
+
148
+# Local configuration file (sdk path, etc)
149
+local.properties
150
+
151
+# Proguard folder generated by Eclipse
152
+android/proguard/
153
+
154
+# Log Files
155
+*.log
156
+
157
+# Android Studio Navigation editor temp files
158
+android/.navigation/
159
+
160
+# Android Studio captures folder
161
+android/captures/
162
+
163
+# Intellij
164
+*.iml
165
+
166
+# Keystore files
167
+*.jks
168
+
169
+##################
170
+# React-Native
171
+##################
1 172
 # OSX
2 173
 #
3 174
 .DS_Store
@@ -32,3 +203,9 @@ local.properties
32 203
 #
33 204
 node_modules/
34 205
 npm-debug.log
206
+
207
+# BUCK
208
+buck-out/
209
+\.buckd/
210
+android/app/libs
211
+android/keystores/debug.keystore

+ 3
- 3
playground/package.json View File

@@ -5,7 +5,7 @@
5 5
   "scripts": {
6 6
     "postinstall": "rm -rf node_modules/react-native-navigation/node_modules && rm -rf node_modules/react-native-navigation/playground",
7 7
     "start": "watchman watch-del-all && (adb reverse tcp:8081 tcp:8081 || true) && node node_modules/react-native/local-cli/cli.js start --reset-cache",
8
-    "xcode": "open ios/example.xcodeproj",
8
+    "xcode": "open ios/playground.xcodeproj",
9 9
     "android": "cd android && ./gradlew installDebug",
10 10
     "e2e": "node ./scripts/e2e.ios.js"
11 11
   },
@@ -21,10 +21,10 @@
21 21
   "detox": {
22 22
     "session": {
23 23
       "server": "ws://localhost:8099",
24
-      "sessionId": "example"
24
+      "sessionId": "playground"
25 25
     },
26 26
     "ios-simulator": {
27
-      "app": "ios/DerivedData/example/Build/Products/Debug_Detox-iphonesimulator/example.app",
27
+      "app": "ios/DerivedData/playground/Build/Products/Debug_Detox-iphonesimulator/playground.app",
28 28
       "device": "iPhone 7, iOS 10.1"
29 29
     }
30 30
   }

+ 1
- 3
src/Navigation.test.js View File

@@ -2,14 +2,12 @@ import _ from 'lodash';
2 2
 
3 3
 describe('Navigation', () => {
4 4
   let Navigation;
5
-  let Commands;
6 5
   let ContainerRegistry;
7 6
 
8 7
   beforeEach(() => {
9 8
     jest.mock('./containers/ContainerRegistry');
10
-    Navigation = require('./Navigation');
11
-    Commands = require('./commands/Commands');
12 9
     ContainerRegistry = require('./containers/ContainerRegistry');
10
+    Navigation = require('./Navigation');
13 11
   });
14 12
 
15 13
   it('exposes static commands', () => {

src/commands/valid-commands.js → src/commands/ValidCommands.test.js View File

@@ -1,10 +1,16 @@
1
-export const singleContainerApp = {
1
+describe('valid commands', () => {
2
+  it('just works', () => {
3
+    //
4
+  });
5
+});
6
+
7
+const singleContainerApp = {
2 8
   container: {
3 9
     key: 'com.example.FirstTabContainer'
4 10
   }
5 11
 };
6 12
 
7
-export const tabBasedApp = {
13
+const tabBasedApp = {
8 14
   tabs: [
9 15
     {
10 16
       container: {
@@ -24,7 +30,7 @@ export const tabBasedApp = {
24 30
   ]
25 31
 };
26 32
 
27
-export const singleWithSideMenu = {
33
+const singleWithSideMenu = {
28 34
   container: {
29 35
     key: 'com.example.MyContainer'
30 36
   },
@@ -35,7 +41,7 @@ export const singleWithSideMenu = {
35 41
   }
36 42
 };
37 43
 
38
-export const singleWithRightSideMenu = {
44
+const singleWithRightSideMenu = {
39 45
   container: {
40 46
     key: 'com.example.MyContainer'
41 47
   },
@@ -46,7 +52,7 @@ export const singleWithRightSideMenu = {
46 52
   }
47 53
 };
48 54
 
49
-export const singleWithBothMenus = {
55
+const singleWithBothMenus = {
50 56
   container: {
51 57
     key: 'com.example.MyContainer'
52 58
   },
@@ -60,7 +66,7 @@ export const singleWithBothMenus = {
60 66
   }
61 67
 };
62 68
 
63
-export const tabBasedWithSideMenu = {
69
+const tabBasedWithSideMenu = {
64 70
   tabs: [
65 71
     {
66 72
       container: {

+ 4
- 8
src/containers/ContainerRegistry.js View File

@@ -1,17 +1,14 @@
1 1
 import React, {Component} from 'react';
2 2
 import {AppRegistry} from 'react-native';
3
-import * as PropsStore from './PropsStore';
4
-import * as ContainerStore from './ContainerStore';
3
+import * as Store from './Store';
5 4
 
6 5
 export function registerContainer(containerKey, getContainerFunc) {
7 6
   const OriginalContainer = getContainerFunc();
8 7
   const NavigationContainer = wrapContainer(containerKey, OriginalContainer);
9
-  ContainerStore.setContainerClass(containerKey, NavigationContainer);
8
+  Store.setContainerClass(containerKey, NavigationContainer);
10 9
   AppRegistry.registerComponent(containerKey, () => NavigationContainer);
11 10
 }
12 11
 
13
-export const bla = {};
14
-
15 12
 function wrapContainer(containerKey, OriginalContainer) {
16 13
   return class extends Component {
17 14
     constructor(props) {
@@ -21,20 +18,19 @@ function wrapContainer(containerKey, OriginalContainer) {
21 18
       }
22 19
       this.state = {
23 20
         containerId: props.containerId,
24
-        allProps: {...props, ...PropsStore.getPropsForContainerId(props.containerId)}
21
+        allProps: {...props, ...Store.getPropsForContainerId(props.containerId)}
25 22
       };
26 23
     }
27 24
 
28 25
     componentWillReceiveProps(nextProps) {
29 26
       this.setState({
30
-        allProps: {...nextProps, ...PropsStore.getPropsForContainerId(this.state.containerId)}
27
+        allProps: {...nextProps, ...Store.getPropsForContainerId(this.state.containerId)}
31 28
       });
32 29
     }
33 30
 
34 31
     render() {
35 32
       return (
36 33
         <OriginalContainer
37
-          ref={(r) => bla.ref = r}
38 34
           {...this.state.allProps}
39 35
           containerId={this.state.containerId}
40 36
         />

+ 13
- 18
src/containers/ContainerRegistry.test.js View File

@@ -2,11 +2,11 @@ import React, {Component} from 'react';
2 2
 import {AppRegistry, Text} from 'react-native';
3 3
 import renderer from 'react-test-renderer';
4 4
 
5
-describe('ComponentRegistry', () => {
5
+describe('ContainerRegistry', () => {
6 6
   let uut;
7
+  let store;
7 8
   let myContainerRef;
8 9
   let testParentRef;
9
-  let containerStore;
10 10
 
11 11
   class MyContainer extends Component {
12 12
     constructor(props) {
@@ -37,12 +37,7 @@ describe('ComponentRegistry', () => {
37 37
 
38 38
   beforeEach(() => {
39 39
     uut = require('./ContainerRegistry');
40
-    containerStore = require('./ContainerStore');
41
-  });
42
-
43
-  afterEach(() => {
44
-    myContainerRef = null;
45
-    testParentRef = null;
40
+    store = require('./Store');
46 41
   });
47 42
 
48 43
   describe('registerContainer', () => {
@@ -65,7 +60,7 @@ describe('ComponentRegistry', () => {
65 60
     });
66 61
   });
67 62
 
68
-  describe('NavigationContainer wrapping', () => {
63
+  describe('NavigationContainer wrapping passed container', () => {
69 64
     const containerKey = 'example.MyContainer';
70 65
 
71 66
     beforeEach(() => {
@@ -73,14 +68,14 @@ describe('ComponentRegistry', () => {
73 68
     });
74 69
 
75 70
     it('must have containerId as prop', () => {
76
-      const NavigationContainer = containerStore.getContainerClass(containerKey);
71
+      const NavigationContainer = store.getContainerClass(containerKey);
77 72
       expect(() => {
78 73
         renderer.create(<NavigationContainer/>);
79 74
       }).toThrow(new Error('Container example.MyContainer does not have a containerId!'));
80 75
     });
81 76
 
82 77
     it('wraps the container and saves to store', () => {
83
-      const NavigationContainer = containerStore.getContainerClass(containerKey);
78
+      const NavigationContainer = store.getContainerClass(containerKey);
84 79
       expect(NavigationContainer).not.toBeInstanceOf(MyContainer);
85 80
       const tree = renderer.create(<NavigationContainer containerId={'container1'}/>);
86 81
       expect(tree.toJSON().children).toEqual(['Hello, World!']);
@@ -88,13 +83,13 @@ describe('ComponentRegistry', () => {
88 83
     });
89 84
 
90 85
     it('injects props from wrapper into original container', () => {
91
-      const NavigationContainer = containerStore.getContainerClass(containerKey);
86
+      const NavigationContainer = store.getContainerClass(containerKey);
92 87
       renderer.create(<NavigationContainer containerId={'container1'} myProp={'yo'}/>);
93 88
       expect(myContainerRef.props.myProp).toEqual('yo');
94 89
     });
95 90
 
96 91
     it('updates props from wrapper into original container', () => {
97
-      const NavigationContainer = containerStore.getContainerClass(containerKey);
92
+      const NavigationContainer = store.getContainerClass(containerKey);
98 93
       renderer.create(<TestParent ChildClass={NavigationContainer}/>);
99 94
       expect(myContainerRef.props.foo).toEqual(undefined);
100 95
       testParentRef.setState({propsFromState: {foo: 'yo'}});
@@ -102,16 +97,16 @@ describe('ComponentRegistry', () => {
102 97
     });
103 98
 
104 99
     it('pulls props from the PropsStore and injects them into the inner container', () => {
105
-      require('./PropsStore').setPropsForContainerId('container123', {numberProp: 1, stringProp: 'hello', objectProp: {a: 2}});
106
-      const NavigationContainer = containerStore.getContainerClass(containerKey);
100
+      store.setPropsForContainerId('container123', {numberProp: 1, stringProp: 'hello', objectProp: {a: 2}});
101
+      const NavigationContainer = store.getContainerClass(containerKey);
107 102
       renderer.create(<NavigationContainer containerId={'container123'}/>);
108 103
       expect(myContainerRef.props).toEqual({containerId: 'container123', numberProp: 1, stringProp: 'hello', objectProp: {a: 2}});
109 104
     });
110 105
 
111 106
     it('updates props from PropsStore into inner container', () => {
112
-      const NavigationContainer = containerStore.getContainerClass(containerKey);
107
+      const NavigationContainer = store.getContainerClass(containerKey);
113 108
       renderer.create(<TestParent ChildClass={NavigationContainer}/>);
114
-      require('./PropsStore').setPropsForContainerId('container1', {myProp: 'hello'});
109
+      store.setPropsForContainerId('container1', {myProp: 'hello'});
115 110
       expect(myContainerRef.props.foo).toEqual(undefined);
116 111
       expect(myContainerRef.props.myProp).toEqual(undefined);
117 112
       testParentRef.setState({propsFromState: {foo: 'yo'}});
@@ -120,7 +115,7 @@ describe('ComponentRegistry', () => {
120 115
     });
121 116
 
122 117
     it('protects containerId from change', () => {
123
-      const NavigationContainer = containerStore.getContainerClass(containerKey);
118
+      const NavigationContainer = store.getContainerClass(containerKey);
124 119
       renderer.create(<TestParent ChildClass={NavigationContainer}/>);
125 120
       expect(myContainerRef.props.containerId).toEqual('container1');
126 121
       testParentRef.setState({propsFromState: {containerId: 'ERROR'}});

+ 0
- 11
src/containers/ContainerStore.js View File

@@ -1,11 +0,0 @@
1
-const state = {
2
-  containersByKey: {}
3
-};
4
-
5
-export function setContainerClass(containerKey, ContainerClass) {
6
-  state.containersByKey[containerKey] = ContainerClass;
7
-}
8
-
9
-export function getContainerClass(containerKey) {
10
-  return state.containersByKey[containerKey];
11
-}

+ 0
- 19
src/containers/ContainerStore.test.js View File

@@ -1,19 +0,0 @@
1
-describe('ContainerStore', () => {
2
-  let uut;
3
-
4
-  beforeEach(() => {
5
-    uut = require('./ContainerStore');
6
-  });
7
-
8
-  class Component {
9
-    //
10
-  }
11
-  class MyComponent extends Component {
12
-    //
13
-  }
14
-
15
-  it('holds containers classes by containerKey', () => {
16
-    uut.setContainerClass('example.mykey', MyComponent);
17
-    expect(uut.getContainerClass('example.mykey')).toEqual(MyComponent);
18
-  });
19
-});

+ 0
- 11
src/containers/PropsStore.js View File

@@ -1,11 +0,0 @@
1
-import _ from 'lodash';
2
-
3
-const propsByContainerId = {};
4
-
5
-export function setPropsForContainerId(containerId, props) {
6
-  _.set(propsByContainerId, containerId, props);
7
-}
8
-
9
-export function getPropsForContainerId(containerId) {
10
-  return _.get(propsByContainerId, containerId, {});
11
-}

+ 22
- 0
src/containers/Store.js View File

@@ -0,0 +1,22 @@
1
+import _ from 'lodash';
2
+
3
+const state = {
4
+  propsByContainerId: {},
5
+  containersByKey: {}
6
+};
7
+
8
+export function setPropsForContainerId(containerId, props) {
9
+  _.set(state.propsByContainerId, containerId, props);
10
+}
11
+
12
+export function getPropsForContainerId(containerId) {
13
+  return _.get(state.propsByContainerId, containerId, {});
14
+}
15
+
16
+export function setContainerClass(containerKey, ContainerClass) {
17
+  state.containersByKey[containerKey] = ContainerClass;
18
+}
19
+
20
+export function getContainerClass(containerKey) {
21
+  return state.containersByKey[containerKey];
22
+}

src/containers/PropsStore.test.js → src/containers/Store.test.js View File

@@ -1,8 +1,8 @@
1
-describe('PropsStore', () => {
1
+describe('Store', () => {
2 2
   let uut;
3 3
 
4 4
   beforeEach(() => {
5
-    uut = require('./PropsStore');
5
+    uut = require('./Store');
6 6
   });
7 7
 
8 8
   it('initial state', () => {
@@ -19,4 +19,13 @@ describe('PropsStore', () => {
19 19
     uut.setPropsForContainerId(undefined, undefined);
20 20
     expect(uut.getPropsForContainerId('container1')).toEqual({});
21 21
   });
22
+
23
+  it('holds containers classes by containerKey', () => {
24
+    const MyComponent = class {
25
+      //
26
+    };
27
+    uut.setContainerClass('example.mykey', MyComponent);
28
+    expect(uut.getContainerClass('example.mykey')).toEqual(MyComponent);
29
+  });
22 30
 });
31
+

+ 2
- 3
src/index.js View File

@@ -1,4 +1,3 @@
1
-import * as NavigationInner from './Navigation';
1
+import * as Navigation from './Navigation';
2 2
 
3
-export default NavigationInner;
4
-export const Navigation = NavigationInner;
3
+export default Navigation;

+ 6
- 6
src/index.test.js View File

@@ -1,14 +1,14 @@
1
+import Navigation from './index';
2
+
1 3
 describe('index', () => {
2 4
   let uut;
3 5
 
4 6
   beforeEach(() => {
5
-    uut = require('./index');
7
+    uut = require('./index').default;
6 8
   });
7 9
 
8
-  it('exposes Navigation as default or as Object', () => {
9
-    expect(uut.Navigation).toBeDefined();
10
-    expect(uut.Navigation).toEqual(uut.default);
11
-    expect(uut.Navigation.startApp).toBeInstanceOf(Function);
12
-    expect(uut.default.startApp).toBeInstanceOf(Function);
10
+  it('exposes Navigation as default', () => {
11
+    expect(uut.startApp).toBeInstanceOf(Function);
12
+    expect(Navigation.startApp).toBeInstanceOf(Function);
13 13
   });
14 14
 });