Selaa lähdekoodia

integration works

Daniel Zlotin 8 vuotta sitten
vanhempi
commit
1e3cd7cdf6

+ 1
- 14
.eslintrc Näytä tiedosto

@@ -426,20 +426,7 @@
426 426
     "react/react-in-jsx-scope": "error",
427 427
     "react/require-extension": 0,
428 428
     "react/self-closing-comp": "error",
429
-    "react/sort-comp": [
430
-      "error",
431
-      {
432
-        "order": [
433
-          "static-methods",
434
-          "lifecycle",
435
-          "/^on.+$/",
436
-          "/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/",
437
-          "everything-else",
438
-          "/^render.+$/",
439
-          "render"
440
-        ]
441
-      }
442
-    ],
429
+    "react/sort-comp": 0,
443 430
     "react/sort-prop-types": 0,
444 431
     "react/jsx-wrap-multilines": "error",
445 432
     "react/jsx-boolean-value": [

+ 1
- 0
.gitignore Näytä tiedosto

@@ -1,3 +1,4 @@
1
+dist
1 2
 
2 3
 ############
3 4
 # Node

+ 1
- 1
.npmignore Näytä tiedosto

@@ -1,5 +1,5 @@
1 1
 playground
2
-
2
+integration
3 3
 
4 4
 
5 5
 

src/env.test.js → integration/env.test.js Näytä tiedosto


+ 36
- 0
integration/remx-support-component.js Näytä tiedosto

@@ -0,0 +1,36 @@
1
+import {Text} from 'react-native';
2
+import React, {Component} from 'react';
3
+
4
+import {connect} from 'remx/react-native';
5
+
6
+import {selectors} from './remx-support-store';
7
+
8
+class MyContainer extends Component {
9
+  constructor(props) {
10
+    super(props);
11
+    this.renders = 0;
12
+  }
13
+
14
+  render() {
15
+    this.renders++;
16
+    if (this.props.printAge) {
17
+      return this.renderAge();
18
+    } else {
19
+      return this.renderName();
20
+    }
21
+  }
22
+
23
+  renderName() {
24
+    return (
25
+      <Text>{selectors.getName()}</Text>
26
+    );
27
+  }
28
+
29
+  renderAge() {
30
+    return (
31
+      <Text>{selectors.getAge()}</Text>
32
+    );
33
+  }
34
+}
35
+
36
+export default connect(MyContainer);

src/integration/remx-support-store.js → integration/remx-support-store.js Näytä tiedosto

@@ -2,17 +2,27 @@ import _ from 'lodash';
2 2
 import * as remx from 'remx';
3 3
 
4 4
 export const state = remx.state({
5
-  person: {}
5
+  person: {
6
+    name: 'no name'
7
+  }
6 8
 });
7 9
 
8 10
 export const mutators = remx.setters({
9 11
   setName(newName) {
10 12
     state.person.name = newName;
13
+  },
14
+
15
+  setAge(age) {
16
+    state.merge({person: {age}});
11 17
   }
12 18
 });
13 19
 
14 20
 export const selectors = remx.getters({
15 21
   getName() {
16
-    return _(state).get('person.name', 'no name');
22
+    return _.get(state, ['person', 'name']);
23
+  },
24
+
25
+  getAge() {
26
+    return _(state).get('person.age');
17 27
   }
18 28
 });

+ 46
- 0
integration/remx-support.test.js Näytä tiedosto

@@ -0,0 +1,46 @@
1
+require('react-native');
2
+import React from 'react';
3
+import renderer from 'react-test-renderer';
4
+
5
+describe('remx support', () => {
6
+  let MyConnectedContainer;
7
+  let store;
8
+
9
+  beforeEach(() => {
10
+    MyConnectedContainer = require('./remx-support-component').default;
11
+    store = require('./remx-support-store');
12
+  });
13
+
14
+  it('renders normally', () => {
15
+    const tree = renderer.create(<MyConnectedContainer/>);
16
+    expect(tree.toJSON().children).toEqual(['no name']);
17
+  });
18
+
19
+  it('rerenders as a result of an underlying state change (by selector)', () => {
20
+    const tree = renderer.create(<MyConnectedContainer/>);
21
+    const instance = tree.getInstance();
22
+
23
+    expect(tree.toJSON().children).toEqual(['no name']);
24
+    expect(instance.renders).toEqual(1);
25
+
26
+    store.mutators.setName('Bob');
27
+    expect(store.selectors.getName()).toEqual('Bob');
28
+    expect(tree.toJSON().children).toEqual(['Bob']);
29
+
30
+    expect(instance.renders).toEqual(2);
31
+  });
32
+
33
+  it('rerenders as a result of an underlying state change with a new key using merge', () => {
34
+    const tree = renderer.create(<MyConnectedContainer printAge={true}/>);
35
+    const instance = tree.getInstance();
36
+
37
+    expect(tree.toJSON().children).toEqual(null);
38
+    expect(instance.renders).toEqual(1);
39
+
40
+    store.mutators.setAge(30);
41
+    expect(store.selectors.getAge()).toEqual(30);
42
+    expect(tree.toJSON().children).toEqual([30]);
43
+
44
+    expect(instance.renders).toEqual(2);
45
+  });
46
+});

+ 4
- 2
package.json Näytä tiedosto

@@ -30,7 +30,7 @@
30 30
     "test-js": "BABEL_ENV=test jest --coverage",
31 31
     "test-android": "cd android && ./gradlew clean testDebugUnitTest",
32 32
     "test-ios": ":",
33
-    "test": "npm run lint && npm run test:js && npm run test:android && npm run test:ios",
33
+    "test": "npm run lint && npm run test-js && npm run test-android && npm run test-ios",
34 34
     "test-watch": "BABEL_ENV=test jest --coverage --watch",
35 35
     "release": ":"
36 36
   },
@@ -57,6 +57,7 @@
57 57
     "jest": "18.x.x",
58 58
     "jest-cli": "18.x.x",
59 59
     "react-test-renderer": "15.4.1",
60
+    "remx": "0.1.x",
60 61
     "semver": "5.x.x"
61 62
   },
62 63
   "babel": {
@@ -73,7 +74,8 @@
73 74
     "preset": "react-native",
74 75
     "testPathDirs": [
75 76
       "node_modules",
76
-      "src"
77
+      "src",
78
+      "integration"
77 79
     ],
78 80
     "resetMocks": true,
79 81
     "resetModules": true

+ 0
- 13
src/integration/env.test.js Näytä tiedosto

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

+ 0
- 22
src/integration/remx-support-component.js Näytä tiedosto

@@ -1,22 +0,0 @@
1
-import {Text} from 'react-native';
2
-import React, {Component} from 'react';
3
-
4
-import {connect} from 'remx/react-native';
5
-
6
-import * as store from './remx-support-store';
7
-
8
-class MyContainer extends Component {
9
-  constructor(props) {
10
-    super(props);
11
-    this.renders = 0;
12
-  }
13
-  render() {
14
-    this.renders++;
15
-    const txt = store.selectors.getName();
16
-    return (
17
-      <Text>{txt}</Text>
18
-    );
19
-  }
20
-}
21
-
22
-export default MyContainer;

+ 0
- 29
src/integration/remx-support.test.js Näytä tiedosto

@@ -1,29 +0,0 @@
1
-xdescribe('remx support', () => {
2
-  let React;
3
-  let renderer;
4
-  let MyConnectedContainer;
5
-  let store;
6
-
7
-  beforeEach(() => {
8
-    require('react-native');
9
-    React = require('react');
10
-    renderer = require('react-test-renderer');
11
-    MyConnectedContainer = require('./remx-support-component').default;
12
-    store = require('./remx-support-store');
13
-  });
14
-
15
-  it('renders normally', () => {
16
-    const tree = renderer.create(<MyConnectedContainer/>);
17
-    expect(tree.toJSON().children).toEqual(['no name']);
18
-  });
19
-
20
-  it('rerenders as a result of an underlying state change (by selector)', () => {
21
-    const tree = renderer.create(<MyConnectedContainer/>);
22
-    const instance = tree.getInstance();
23
-    expect(tree.toJSON().children).toEqual(['no name']);
24
-    expect(instance.renders).toEqual(1);
25
-    store.mutators.setName('Bob');
26
-    expect(tree.toJSON().children).toEqual(['no name']);
27
-    expect(instance.renders).toEqual(2);
28
-  });
29
-});

+ 5
- 2
wallaby.js Näytä tiedosto

@@ -14,11 +14,14 @@ module.exports = function(wallaby) {
14 14
     files: [
15 15
       'package.json',
16 16
       'src/**/*.js',
17
-      '!src/**/*.test.js'
17
+      '!src/**/*.test.js',
18
+      'integration/**/*.js',
19
+      '!integration/**/*.test.js'
18 20
     ],
19 21
 
20 22
     tests: [
21
-      'src/**/*.test.js'
23
+      'src/**/*.test.js',
24
+      'integration/**/*.test.js'
22 25
     ],
23 26
 
24 27
     compilers: {

+ 27
- 1
yarn.lock Näytä tiedosto

@@ -1662,7 +1662,11 @@ dom-walk@^0.1.0:
1662 1662
   version "0.1.1"
1663 1663
   resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
1664 1664
 
1665
-domelementtype@1, domelementtype@~1.1.1:
1665
+domelementtype@1:
1666
+  version "1.3.0"
1667
+  resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.3.0.tgz#b17aed82e8ab59e52dd9c19b1756e0fc187204c2"
1668
+
1669
+domelementtype@~1.1.1:
1666 1670
   version "1.1.3"
1667 1671
   resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.1.3.tgz#bd28773e2642881aec51544924299c5cd822185b"
1668 1672
 
@@ -2623,6 +2627,10 @@ hoek@2.x.x:
2623 2627
   version "2.16.3"
2624 2628
   resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
2625 2629
 
2630
+hoist-non-react-statics@^1.2.0:
2631
+  version "1.2.0"
2632
+  resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz#aa448cf0986d55cc40773b17174b7dd066cb7cfb"
2633
+
2626 2634
 home-or-tmp@^2.0.0:
2627 2635
   version "2.0.0"
2628 2636
   resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8"
@@ -3781,6 +3789,16 @@ minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0:
3781 3789
   dependencies:
3782 3790
     minimist "0.0.8"
3783 3791
 
3792
+mobx-react@3.x.x:
3793
+  version "3.5.9"
3794
+  resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-3.5.9.tgz#b710299539d58d7af1189b5e86bc0be4198a43c1"
3795
+  dependencies:
3796
+    hoist-non-react-statics "^1.2.0"
3797
+
3798
+mobx@2.x.x:
3799
+  version "2.7.0"
3800
+  resolved "https://registry.yarnpkg.com/mobx/-/mobx-2.7.0.tgz#cf3d82d18c0ca7f458d8f2a240817b3dc7e54a01"
3801
+
3784 3802
 module-deps@^3.9.1:
3785 3803
   version "3.9.1"
3786 3804
   resolved "https://registry.yarnpkg.com/module-deps/-/module-deps-3.9.1.tgz#ea75caf9199090d25b0d5512b5acacb96e7f87f3"
@@ -4559,6 +4577,14 @@ regjsparser@^0.1.4:
4559 4577
   dependencies:
4560 4578
     jsesc "~0.5.0"
4561 4579
 
4580
+remx@0.1.x:
4581
+  version "0.1.35"
4582
+  resolved "https://registry.yarnpkg.com/remx/-/remx-0.1.35.tgz#dc8e8fa2c9b28805213dad85f647f64f4a78adf5"
4583
+  dependencies:
4584
+    lodash "4.x.x"
4585
+    mobx "2.x.x"
4586
+    mobx-react "3.x.x"
4587
+
4562 4588
 repeat-element@^1.1.2:
4563 4589
   version "1.1.2"
4564 4590
   resolved "https://registry.yarnpkg.com/repeat-element/-/repeat-element-1.1.2.tgz#ef089a178d1483baae4d93eb98b4f9e4e11d990a"