Daniel Zlotin 8 years ago
parent
commit
93d9cbb1db

+ 2
- 19
.eslintrc View File

302
     "no-whitespace-before-property": "error",
302
     "no-whitespace-before-property": "error",
303
     "object-curly-spacing": [
303
     "object-curly-spacing": [
304
       "error",
304
       "error",
305
-      "never"
305
+      "always"
306
     ],
306
     ],
307
     "one-var": 0,
307
     "one-var": 0,
308
     "one-var-declaration-per-line": 0,
308
     "one-var-declaration-per-line": 0,
481
      *                              react-native plugin
481
      *                              react-native plugin
482
      */
482
      */
483
     "react-native/no-unused-styles": "error",
483
     "react-native/no-unused-styles": "error",
484
-    "react-native/split-platform-components": "error",
485
-    /*
486
-     *                              babel plugin
487
-     */
488
-    "babel/new-cap": [
489
-      "error",
490
-      {
491
-        "capIsNewExceptions": [
492
-          "Immutable"
493
-        ]
494
-      }
495
-    ],
496
-    "babel/object-curly-spacing": [
497
-      "error",
498
-      "never"
499
-    ],
500
-    "babel/object-shorthand": 0,
501
-    "babel/no-await-in-loop": 0
484
+    "react-native/split-platform-components": "error"
502
   }
485
   }
503
 }
486
 }

+ 3
- 3
integration/env.test.js View File

1
 describe('test environment', () => {
1
 describe('test environment', () => {
2
   it('handles object spread', () => {
2
   it('handles object spread', () => {
3
-    const {x, y, ...z} = {x: 1, y: 2, a: 3, b: 4};
3
+    const { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
4
     expect(x).toEqual(1);
4
     expect(x).toEqual(1);
5
     expect(y).toEqual(2);
5
     expect(y).toEqual(2);
6
-    expect(z).toEqual({a: 3, b: 4});
6
+    expect(z).toEqual({ a: 3, b: 4 });
7
   });
7
   });
8
 
8
 
9
-  it('handles async await', async() => {
9
+  it('handles async await', async () => {
10
     const result = await new Promise((r) => r('hello'));
10
     const result = await new Promise((r) => r('hello'));
11
     expect(result).toEqual('hello');
11
     expect(result).toEqual('hello');
12
   });
12
   });

+ 4
- 4
integration/remx/component.js View File

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

+ 1
- 1
integration/remx/store.js View File

13
   },
13
   },
14
 
14
 
15
   setAge(age) {
15
   setAge(age) {
16
-    state.merge({person: {age}});
16
+    state.merge({ person: { age } });
17
   }
17
   }
18
 });
18
 });
19
 
19
 

+ 9
- 4
jsconfig.json View File

1
 {
1
 {
2
     "compilerOptions": {
2
     "compilerOptions": {
3
         "allowJs": true,
3
         "allowJs": true,
4
-        "allowSyntheticDefaultImports": true
4
+        "allowSyntheticDefaultImports": true,
5
+        "target": "ES6"
5
     },
6
     },
6
     "exclude": [
7
     "exclude": [
7
-        "node_modules"
8
-    ]
9
-}
8
+        "node_modules",
9
+        "playground/node_modules"
10
+    ],
11
+    "react-native-tools": {
12
+        "projectRoot": "./"
13
+    }
14
+}

+ 1
- 1
package.json View File

26
   "main": "src/index.js",
26
   "main": "src/index.js",
27
   "scripts": {
27
   "scripts": {
28
     "build": ":",
28
     "build": ":",
29
-    "lint": "eslint src",
29
+    "lint": "eslint src integration scripts playground/src playground/e2e playground/scripts",
30
     "test-js": "BABEL_ENV=test jest --coverage",
30
     "test-js": "BABEL_ENV=test jest --coverage",
31
     "test-android": "node ./scripts/test.android.js",
31
     "test-android": "node ./scripts/test.android.js",
32
     "test-ios": "node ./scripts/test.ios.js",
32
     "test-ios": "node ./scripts/test.ios.js",

+ 1
- 1
playground/e2e/app.test.js View File

7
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
7
     expect(elementByLabel('React Native Navigation!')).toBeVisible();
8
   });
8
   });
9
 
9
 
10
-  xit('switch to tab based app', () => {
10
+  it('switch to tab based app', () => {
11
     elementByLabel('Switch to tab based app').tap();
11
     elementByLabel('Switch to tab based app').tap();
12
     expect(elementByLabel('This is a tab screen')).toBeVisible();
12
     expect(elementByLabel('This is a tab screen')).toBeVisible();
13
   });
13
   });

+ 3
- 3
playground/e2e/init.js View File

5
 
5
 
6
 detoxConfig['ios-simulator'].app = process.env.detoxAppBuildPath;
6
 detoxConfig['ios-simulator'].app = process.env.detoxAppBuildPath;
7
 
7
 
8
-before(function(done) {
8
+before(function (done) {
9
   detox.config(detoxConfig);
9
   detox.config(detoxConfig);
10
   detox.start(done);
10
   detox.start(done);
11
 });
11
 });
12
 
12
 
13
-afterEach(function(done) {
13
+afterEach(function (done) {
14
   detox.waitForTestResult(done);
14
   detox.waitForTestResult(done);
15
 });
15
 });
16
 
16
 
17
-after(function(done) {
17
+after(function (done) {
18
   detox.cleanup(done);
18
   detox.cleanup(done);
19
 });
19
 });

+ 1
- 1
playground/src/app.js View File

1
 import Navigation from 'react-native-navigation';
1
 import Navigation from 'react-native-navigation';
2
 
2
 
3
-import {registerContainers} from './containers';
3
+import { registerContainers } from './containers';
4
 
4
 
5
 export function start() {
5
 export function start() {
6
   registerContainers();
6
   registerContainers();

+ 2
- 2
playground/src/containers/SimpleTabScreen.js View File

1
-import React, {Component} from 'react';
2
-import {View, Text} from 'react-native';
1
+import React, { Component } from 'react';
2
+import { View, Text } from 'react-native';
3
 
3
 
4
 export default class SimpleTabScreen extends Component {
4
 export default class SimpleTabScreen extends Component {
5
   render() {
5
   render() {

+ 5
- 2
playground/src/containers/WelcomeScreen.js View File

1
-import React, {Component} from 'react';
2
-import {View, Text} from 'react-native';
1
+import React, { Component } from 'react';
2
+import { View, Text, Button } from 'react-native';
3
 
3
 
4
 export default class WelcomeScreen extends Component {
4
 export default class WelcomeScreen extends Component {
5
   render() {
5
   render() {
6
     return (
6
     return (
7
       <View style={styles.root}>
7
       <View style={styles.root}>
8
         <Text style={styles.h1}>{`React Native Navigation!`}</Text>
8
         <Text style={styles.h1}>{`React Native Navigation!`}</Text>
9
+        <Button>
10
+          <Text style={styles.h1}>{`Switch to tab based app`}</Text>
11
+        </Button>
9
       </View>
12
       </View>
10
     );
13
     );
11
   }
14
   }

+ 1
- 1
playground/src/index.js View File

1
-import {start} from './app';
1
+import { start } from './app';
2
 
2
 
3
 start();
3
 start();

+ 1
- 0
scripts/release.js View File

1
+/*eslint-disable no-console*/
1
 const shellUtils = require('shell-utils');
2
 const shellUtils = require('shell-utils');
2
 const p = require('path');
3
 const p = require('path');
3
 const semver = require('semver');
4
 const semver = require('semver');

+ 1
- 1
src/adapters/NativeCommandsSender.js View File

1
-import {NativeModules} from 'react-native';
1
+import { NativeModules } from 'react-native';
2
 
2
 
3
 export default class NativeCommandsSender {
3
 export default class NativeCommandsSender {
4
   constructor() {
4
   constructor() {

+ 1
- 1
src/adapters/NativeEventsReceiver.js View File

1
-import {NativeModules, NativeEventEmitter} from 'react-native';
1
+import { NativeModules, NativeEventEmitter } from 'react-native';
2
 
2
 
3
 export default class NativeEventsReceiver {
3
 export default class NativeEventsReceiver {
4
   constructor() {
4
   constructor() {

+ 1
- 1
src/adapters/NativeEventsReceiver.test.js View File

1
 describe('NativeEventsReceiver', () => {
1
 describe('NativeEventsReceiver', () => {
2
   let uut;
2
   let uut;
3
-  const eventEmitterMock = {addListener: jest.fn()};
3
+  const eventEmitterMock = { addListener: jest.fn() };
4
 
4
 
5
   beforeEach(() => {
5
   beforeEach(() => {
6
     require('react-native').NativeModules.RNNEventEmitter = {};
6
     require('react-native').NativeModules.RNNEventEmitter = {};

+ 3
- 3
src/commands/LayoutTreeParser.test.js View File

4
   let uut;
4
   let uut;
5
 
5
 
6
   beforeEach(() => {
6
   beforeEach(() => {
7
-    const uniqueIdProvider = {generate: (prefix) => `${prefix}+UNIQUE_ID`};
7
+    const uniqueIdProvider = { generate: (prefix) => `${prefix}+UNIQUE_ID` };
8
     const LayoutTreeParser = require('./LayoutTreeParser').default;
8
     const LayoutTreeParser = require('./LayoutTreeParser').default;
9
     uut = new LayoutTreeParser(uniqueIdProvider);
9
     uut = new LayoutTreeParser(uniqueIdProvider);
10
   });
10
   });
108
   });
108
   });
109
 
109
 
110
   xit('adds uniqueId to containers', () => {
110
   xit('adds uniqueId to containers', () => {
111
-    const input = {container: {}};
112
-    expect(uut.parse(input)).toEqual({container: {id: 'Container+UNIQUE_ID'}});
111
+    const input = { container: {} };
112
+    expect(uut.parse(input)).toEqual({ container: { id: 'Container+UNIQUE_ID' } });
113
   });
113
   });
114
 
114
 
115
   xit('parses side menus', () => {
115
   xit('parses side menus', () => {

+ 1
- 1
src/containers/ContainerRegistry.js View File

1
-import {AppRegistry} from 'react-native';
1
+import { AppRegistry } from 'react-native';
2
 import ContainerWrapper from './ContainerWrapper';
2
 import ContainerWrapper from './ContainerWrapper';
3
 
3
 
4
 export default class ContainerRegistry {
4
 export default class ContainerRegistry {

+ 3
- 3
src/containers/ContainerRegistry.test.js View File

1
-import React, {Component} from 'react';
2
-import {AppRegistry, Text} from 'react-native';
1
+import React, { Component } from 'react';
2
+import { AppRegistry, Text } from 'react-native';
3
 import renderer from 'react-test-renderer';
3
 import renderer from 'react-test-renderer';
4
 
4
 
5
 describe('ContainerRegistry', () => {
5
 describe('ContainerRegistry', () => {
28
   it('resulting in a normal component', () => {
28
   it('resulting in a normal component', () => {
29
     uut.registerContainer('example.MyContainer.name', () => MyContainer);
29
     uut.registerContainer('example.MyContainer.name', () => MyContainer);
30
     const Container = AppRegistry.registerComponent.mock.calls[0][1]();
30
     const Container = AppRegistry.registerComponent.mock.calls[0][1]();
31
-    const tree = renderer.create(<Container containerId="123"/>);
31
+    const tree = renderer.create(<Container containerId="123" />);
32
     expect(tree.toJSON().children).toEqual(['Hello, World!']);
32
     expect(tree.toJSON().children).toEqual(['Hello, World!']);
33
   });
33
   });
34
 });
34
 });

+ 3
- 3
src/containers/ContainerWrapper.js View File

1
-import React, {Component} from 'react';
1
+import React, { Component } from 'react';
2
 
2
 
3
 export default class ContainerWrapper {
3
 export default class ContainerWrapper {
4
   static wrap(containerName, OriginalContainer, propStore) {
4
   static wrap(containerName, OriginalContainer, propStore) {
10
         }
10
         }
11
         this.state = {
11
         this.state = {
12
           containerId: props.containerId,
12
           containerId: props.containerId,
13
-          allProps: {...props, ...propStore.getPropsForContainerId(props.containerId)}
13
+          allProps: { ...props, ...propStore.getPropsForContainerId(props.containerId) }
14
         };
14
         };
15
       }
15
       }
16
 
16
 
17
       componentWillReceiveProps(nextProps) {
17
       componentWillReceiveProps(nextProps) {
18
         this.setState({
18
         this.setState({
19
-          allProps: {...nextProps, ...propStore.getPropsForContainerId(this.state.containerId)}
19
+          allProps: { ...nextProps, ...propStore.getPropsForContainerId(this.state.containerId) }
20
         });
20
         });
21
       }
21
       }
22
 
22
 

+ 17
- 17
src/containers/ContainerWrapper.test.js View File

1
-import React, {Component} from 'react';
2
-import {AppRegistry, Text} from 'react-native';
1
+import React, { Component } from 'react';
2
+import { AppRegistry, Text } from 'react-native';
3
 import renderer from 'react-test-renderer';
3
 import renderer from 'react-test-renderer';
4
 
4
 
5
 describe('ContainerWrapper', () => {
5
 describe('ContainerWrapper', () => {
25
       super(props);
25
       super(props);
26
       testParentRef = this; //eslint-disable-line
26
       testParentRef = this; //eslint-disable-line
27
       this.ChildClass = props.ChildClass;
27
       this.ChildClass = props.ChildClass;
28
-      this.state = {propsFromState: {}};
28
+      this.state = { propsFromState: {} };
29
     }
29
     }
30
 
30
 
31
     render() {
31
     render() {
32
       const Child = this.ChildClass;
32
       const Child = this.ChildClass;
33
       return (
33
       return (
34
-        <Child containerId="container1" {...this.state.propsFromState}/>
34
+        <Child containerId="container1" {...this.state.propsFromState} />
35
       );
35
       );
36
     }
36
     }
37
   }
37
   }
45
   it('must have containerId as prop', () => {
45
   it('must have containerId as prop', () => {
46
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
46
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
47
     expect(() => {
47
     expect(() => {
48
-      renderer.create(<NavigationContainer/>);
48
+      renderer.create(<NavigationContainer />);
49
     }).toThrow(new Error('Container example.MyContainer does not have a containerId!'));
49
     }).toThrow(new Error('Container example.MyContainer does not have a containerId!'));
50
   });
50
   });
51
 
51
 
52
   it('wraps the container and saves to store', () => {
52
   it('wraps the container and saves to store', () => {
53
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
53
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
54
     expect(NavigationContainer).not.toBeInstanceOf(MyContainer);
54
     expect(NavigationContainer).not.toBeInstanceOf(MyContainer);
55
-    const tree = renderer.create(<NavigationContainer containerId={'container1'}/>);
55
+    const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
56
     expect(tree.toJSON().children).toEqual(['Hello, World!']);
56
     expect(tree.toJSON().children).toEqual(['Hello, World!']);
57
     expect(myContainerRef).toBeInstanceOf(MyContainer);
57
     expect(myContainerRef).toBeInstanceOf(MyContainer);
58
   });
58
   });
59
 
59
 
60
   it('injects props from wrapper into original container', () => {
60
   it('injects props from wrapper into original container', () => {
61
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
61
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
62
-    renderer.create(<NavigationContainer containerId={'container1'} myProp={'yo'}/>);
62
+    renderer.create(<NavigationContainer containerId={'container1'} myProp={'yo'} />);
63
     expect(myContainerRef.props.myProp).toEqual('yo');
63
     expect(myContainerRef.props.myProp).toEqual('yo');
64
   });
64
   });
65
 
65
 
66
   it('updates props from wrapper into original container', () => {
66
   it('updates props from wrapper into original container', () => {
67
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
67
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
68
-    renderer.create(<TestParent ChildClass={NavigationContainer}/>);
68
+    renderer.create(<TestParent ChildClass={NavigationContainer} />);
69
     expect(myContainerRef.props.foo).toEqual(undefined);
69
     expect(myContainerRef.props.foo).toEqual(undefined);
70
-    testParentRef.setState({propsFromState: {foo: 'yo'}});
70
+    testParentRef.setState({ propsFromState: { foo: 'yo' } });
71
     expect(myContainerRef.props.foo).toEqual('yo');
71
     expect(myContainerRef.props.foo).toEqual('yo');
72
   });
72
   });
73
 
73
 
74
   it('pulls props from the store and injects them into the inner container', () => {
74
   it('pulls props from the store and injects them into the inner container', () => {
75
-    store.setPropsForContainerId('container123', {numberProp: 1, stringProp: 'hello', objectProp: {a: 2}});
75
+    store.setPropsForContainerId('container123', { numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
76
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
76
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
77
-    renderer.create(<NavigationContainer containerId={'container123'}/>);
78
-    expect(myContainerRef.props).toEqual({containerId: 'container123', numberProp: 1, stringProp: 'hello', objectProp: {a: 2}});
77
+    renderer.create(<NavigationContainer containerId={'container123'} />);
78
+    expect(myContainerRef.props).toEqual({ containerId: 'container123', numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
79
   });
79
   });
80
 
80
 
81
   it('updates props from store into inner container', () => {
81
   it('updates props from store into inner container', () => {
82
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
82
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
83
-    renderer.create(<TestParent ChildClass={NavigationContainer}/>);
84
-    store.setPropsForContainerId('container1', {myProp: 'hello'});
83
+    renderer.create(<TestParent ChildClass={NavigationContainer} />);
84
+    store.setPropsForContainerId('container1', { myProp: 'hello' });
85
     expect(myContainerRef.props.foo).toEqual(undefined);
85
     expect(myContainerRef.props.foo).toEqual(undefined);
86
     expect(myContainerRef.props.myProp).toEqual(undefined);
86
     expect(myContainerRef.props.myProp).toEqual(undefined);
87
-    testParentRef.setState({propsFromState: {foo: 'yo'}});
87
+    testParentRef.setState({ propsFromState: { foo: 'yo' } });
88
     expect(myContainerRef.props.foo).toEqual('yo');
88
     expect(myContainerRef.props.foo).toEqual('yo');
89
     expect(myContainerRef.props.myProp).toEqual('hello');
89
     expect(myContainerRef.props.myProp).toEqual('hello');
90
   });
90
   });
91
 
91
 
92
   it('protects containerId from change', () => {
92
   it('protects containerId from change', () => {
93
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
93
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
94
-    renderer.create(<TestParent ChildClass={NavigationContainer}/>);
94
+    renderer.create(<TestParent ChildClass={NavigationContainer} />);
95
     expect(myContainerRef.props.containerId).toEqual('container1');
95
     expect(myContainerRef.props.containerId).toEqual('container1');
96
-    testParentRef.setState({propsFromState: {containerId: 'ERROR'}});
96
+    testParentRef.setState({ propsFromState: { containerId: 'ERROR' } });
97
     expect(myContainerRef.props.containerId).toEqual('container1');
97
     expect(myContainerRef.props.containerId).toEqual('container1');
98
   });
98
   });
99
 });
99
 });

+ 2
- 2
src/containers/Store.test.js View File

11
   });
11
   });
12
 
12
 
13
   it('holds props by containerId', () => {
13
   it('holds props by containerId', () => {
14
-    uut.setPropsForContainerId('container1', {a: 1, b: 2});
15
-    expect(uut.getPropsForContainerId('container1')).toEqual({a: 1, b: 2});
14
+    uut.setPropsForContainerId('container1', { a: 1, b: 2 });
15
+    expect(uut.getPropsForContainerId('container1')).toEqual({ a: 1, b: 2 });
16
   });
16
   });
17
 
17
 
18
   it('defensive for invalid containerId and props', () => {
18
   it('defensive for invalid containerId and props', () => {

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

1
-jest.mock('./Navigation', () => ({startApp: () => 'import'}));
1
+jest.mock('./Navigation', () => ({ startApp: () => 'import' }));
2
 import Navigation from './index';
2
 import Navigation from './index';
3
 
3
 
4
 describe('index', () => {
4
 describe('index', () => {
5
   let uut;
5
   let uut;
6
 
6
 
7
   beforeEach(() => {
7
   beforeEach(() => {
8
-    jest.mock('./Navigation', () => ({startApp: () => 'require'}));
8
+    jest.mock('./Navigation', () => ({ startApp: () => 'require' }));
9
     uut = require('./index');
9
     uut = require('./index');
10
   });
10
   });
11
 
11