Browse Source

start of something beautiful

Daniel Zlotin 8 years ago
parent
commit
170f4359eb

+ 3
- 1
package.json View File

@@ -49,7 +49,9 @@
49 49
     "eslint-plugin-react": "6.x.x",
50 50
     "eslint-plugin-react-native": "2.x.x",
51 51
     "jest": "17.x.x",
52
-    "jest-cli": "17.x.x"
52
+    "jest-cli": "17.x.x",
53
+    "jest-react-native": "17.x.x",
54
+    "react-test-renderer": "15.3.2"
53 55
   },
54 56
   "jest": {
55 57
     "resetMocks": true,

+ 42
- 0
src2/Navigation.js View File

@@ -1 +1,43 @@
1
+export function registerContainer(params) {
2
+  //
3
+}
1 4
 
5
+export function startApp(params) {
6
+  //
7
+}
8
+
9
+export function push(params) {
10
+  //
11
+}
12
+
13
+export function pop(params) {
14
+  //
15
+}
16
+
17
+export function showModal(params) {
18
+  //
19
+}
20
+
21
+export function dismissModal(params) {
22
+  //
23
+}
24
+
25
+export function dismissAllModals(params) {
26
+  //
27
+}
28
+
29
+export function showLightbox(params) {
30
+  //
31
+}
32
+
33
+export function dismissLightbox(params) {
34
+  //
35
+}
36
+
37
+export function showInAppNotification(params) {
38
+  //
39
+}
40
+
41
+export function dismissInAppNotification(params) {
42
+  //
43
+}

+ 25
- 0
src2/Navigation.test.js View File

@@ -0,0 +1,25 @@
1
+import _ from 'lodash';
2
+
3
+describe('Navigation', () => {
4
+  let Navigation;
5
+
6
+  beforeEach(() => {
7
+    Navigation = require('./Navigation');
8
+  });
9
+
10
+  it('exposes static commands', () => {
11
+    _.forEach([
12
+      Navigation.registerContainer,
13
+      Navigation.startApp,
14
+      Navigation.push,
15
+      Navigation.pop,
16
+      Navigation.showModal,
17
+      Navigation.dismissModal,
18
+      Navigation.dismissAllModals,
19
+      Navigation.showLightbox,
20
+      Navigation.dismissLightbox,
21
+      Navigation.showInAppNotification,
22
+      Navigation.dismissInAppNotification
23
+    ], (f) => expect(f).toBeInstanceOf(Function));
24
+  });
25
+});

+ 22
- 0
src2/containers/ContainerRegistry.js View File

@@ -0,0 +1,22 @@
1
+import React from 'react';
2
+import {AppRegistry, Component} from 'react-native';
3
+
4
+export function registerContainer(containerKey, getContainerFunc) {
5
+  const OrigContainer = getContainerFunc();
6
+  const WrappedContainer = wrapContainer(OrigContainer);
7
+  AppRegistry.registerComponent(containerKey, () => WrappedContainer);
8
+}
9
+
10
+function wrapContainer(OrigComponent) {
11
+  return class extends Component {
12
+    //constructor(props) {
13
+    //  super(props);
14
+    //}
15
+
16
+    render() {
17
+      return (
18
+        <OrigComponent/>
19
+      );
20
+    }
21
+  };
22
+}

+ 29
- 0
src2/containers/ContainerRegistry.test.js View File

@@ -0,0 +1,29 @@
1
+describe('ComponentRegistry', () => {
2
+  let uut;
3
+  let AppRegistry;
4
+  let MyContainer, Component;
5
+
6
+  beforeEach(() => {
7
+    AppRegistry = {registerComponent: jest.fn()};
8
+    Component = class {
9
+      //
10
+    };
11
+
12
+    jest.mock('react', () => ({}));
13
+    jest.mock('react-native', () => ({AppRegistry, Component}));
14
+    uut = require('./ContainerRegistry');
15
+
16
+    MyContainer = class extends Component {
17
+      //
18
+    };
19
+  });
20
+
21
+  it('registers container component into AppRegistry', () => {
22
+    expect(AppRegistry.registerComponent).not.toHaveBeenCalled();
23
+
24
+    uut.registerContainer('example.MyContainer', () => MyContainer);
25
+
26
+    expect(AppRegistry.registerComponent).toHaveBeenCalledTimes(1);
27
+    expect(AppRegistry.registerComponent.mock.calls[0][0]).toEqual('example.MyContainer');
28
+  });
29
+});

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

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

+ 22
- 0
src2/containers/PropsStore.test.js View File

@@ -0,0 +1,22 @@
1
+describe('PropsStore', () => {
2
+  let uut;
3
+
4
+  beforeEach(() => {
5
+    uut = require('./PropsStore');
6
+  });
7
+
8
+  it('initial state', () => {
9
+    expect(uut.getPropsForScreenId('screen1')).toEqual({});
10
+  });
11
+
12
+  it('holds props by screenId', () => {
13
+    uut.setPropsForScreenId('screen1', {a: 1, b: 2});
14
+    expect(uut.getPropsForScreenId('screen1')).toEqual({a: 1, b: 2});
15
+  });
16
+
17
+  it('defensive for invalid screenId and props', () => {
18
+    uut.setPropsForScreenId('screen1', undefined);
19
+    uut.setPropsForScreenId(undefined, undefined);
20
+    expect(uut.getPropsForScreenId('screen1')).toEqual({});
21
+  });
22
+});

+ 0
- 17
src2/stores/props/store.js View File

@@ -1,17 +0,0 @@
1
-import _ from 'lodash';
2
-
3
-const state = {
4
-  propsByScreenId: {}
5
-};
6
-
7
-export const mutators = {
8
-  setPropsForScreenId(screenId, props) {
9
-    _.set(state.propsByScreenId, screenId, props);
10
-  }
11
-};
12
-
13
-export const selectors = {
14
-  getPropsForScreenId(screenId) {
15
-    return _.get(state.propsByScreenId, screenId, {});
16
-  }
17
-};

+ 0
- 22
src2/stores/props/store.test.js View File

@@ -1,22 +0,0 @@
1
-describe('stores/props/store', () => {
2
-  let uut;
3
-
4
-  beforeEach(() => {
5
-    uut = require('./store');
6
-  });
7
-
8
-  it('initial state', () => {
9
-    expect(uut.selectors.getPropsForScreenId('screen1')).toEqual({});
10
-  });
11
-
12
-  it('holds props by screenId', () => {
13
-    uut.mutators.setPropsForScreenId('screen1', {a: 1, b: 2});
14
-    expect(uut.selectors.getPropsForScreenId('screen1')).toEqual({a: 1, b: 2});
15
-  });
16
-
17
-  it('defensive for invalid screenId and props', () => {
18
-    uut.mutators.setPropsForScreenId('screen1', undefined);
19
-    uut.mutators.setPropsForScreenId(undefined, undefined);
20
-    expect(uut.selectors.getPropsForScreenId('screen1')).toEqual({});
21
-  });
22
-});

+ 36
- 31
yarn.lock View File

@@ -304,12 +304,12 @@ babel-eslint@6.1.2:
304 304
     lodash.pickby "^4.0.0"
305 305
 
306 306
 babel-generator@^6.17.0, babel-generator@^6.18.0:
307
-  version "6.18.0"
308
-  resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.18.0.tgz#e4f104cb3063996d9850556a45aae4a022060a07"
307
+  version "6.19.0"
308
+  resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.19.0.tgz#9b2f244204777a3d6810ec127c673c87b349fac5"
309 309
   dependencies:
310 310
     babel-messages "^6.8.0"
311 311
     babel-runtime "^6.9.0"
312
-    babel-types "^6.18.0"
312
+    babel-types "^6.19.0"
313 313
     detect-indent "^4.0.0"
314 314
     jsesc "^1.3.0"
315 315
     lodash "^4.2.0"
@@ -469,12 +469,13 @@ babel-plugin-syntax-trailing-function-commas@^6.13.0, babel-plugin-syntax-traili
469 469
   resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.13.0.tgz#2b84b7d53dd744f94ff1fad7669406274b23f541"
470 470
 
471 471
 babel-plugin-transform-class-properties@^6.5.0, babel-plugin-transform-class-properties@^6.6.0, babel-plugin-transform-class-properties@^6.8.0:
472
-  version "6.18.0"
473
-  resolved "https://registry.yarnpkg.com/babel-plugin-transform-class-properties/-/babel-plugin-transform-class-properties-6.18.0.tgz#bc1266a39d4c8726e0bd7b15c56235177e6ede57"
472
+  version "6.19.0"
473
+  resolved "https://registry.yarnpkg.com/babel-plugin-transform-class-properties/-/babel-plugin-transform-class-properties-6.19.0.tgz#1274b349abaadc835164e2004f4a2444a2788d5f"
474 474
   dependencies:
475 475
     babel-helper-function-name "^6.18.0"
476 476
     babel-plugin-syntax-class-properties "^6.8.0"
477 477
     babel-runtime "^6.9.1"
478
+    babel-template "^6.15.0"
478 479
 
479 480
 babel-plugin-transform-es2015-arrow-functions@^6.5.0, babel-plugin-transform-es2015-arrow-functions@^6.5.2, babel-plugin-transform-es2015-arrow-functions@^6.8.0:
480 481
   version "6.8.0"
@@ -521,8 +522,8 @@ babel-plugin-transform-es2015-computed-properties@^6.5.0, babel-plugin-transform
521 522
     babel-template "^6.8.0"
522 523
 
523 524
 babel-plugin-transform-es2015-destructuring@6.x, babel-plugin-transform-es2015-destructuring@^6.5.0, babel-plugin-transform-es2015-destructuring@^6.6.5, babel-plugin-transform-es2015-destructuring@^6.8.0:
524
-  version "6.18.0"
525
-  resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-destructuring/-/babel-plugin-transform-es2015-destructuring-6.18.0.tgz#a08fb89415ab82058649558bedb7bf8dafa76ba5"
525
+  version "6.19.0"
526
+  resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-destructuring/-/babel-plugin-transform-es2015-destructuring-6.19.0.tgz#ff1d911c4b3f4cab621bd66702a869acd1900533"
526 527
   dependencies:
527 528
     babel-runtime "^6.9.0"
528 529
 
@@ -634,8 +635,8 @@ babel-plugin-transform-object-assign@^6.5.0:
634 635
     babel-runtime "^6.0.0"
635 636
 
636 637
 babel-plugin-transform-object-rest-spread@^6.16.0, babel-plugin-transform-object-rest-spread@^6.5.0, babel-plugin-transform-object-rest-spread@^6.6.5, babel-plugin-transform-object-rest-spread@^6.8.0:
637
-  version "6.16.0"
638
-  resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.16.0.tgz#db441d56fffc1999052fdebe2e2f25ebd28e36a9"
638
+  version "6.19.0"
639
+  resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.19.0.tgz#f6ac428ee3cb4c6aa00943ed1422ce813603b34c"
639 640
   dependencies:
640 641
     babel-plugin-syntax-object-rest-spread "^6.8.0"
641 642
     babel-runtime "^6.0.0"
@@ -830,22 +831,22 @@ babel-template@^6.14.0, babel-template@^6.15.0, babel-template@^6.16.0, babel-te
830 831
     lodash "^4.2.0"
831 832
 
832 833
 babel-traverse@^6.0.20, babel-traverse@^6.16.0, babel-traverse@^6.18.0:
833
-  version "6.18.0"
834
-  resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.18.0.tgz#5aeaa980baed2a07c8c47329cd90c3b90c80f05e"
834
+  version "6.19.0"
835
+  resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.19.0.tgz#68363fb821e26247d52a519a84b2ceab8df4f55a"
835 836
   dependencies:
836 837
     babel-code-frame "^6.16.0"
837 838
     babel-messages "^6.8.0"
838 839
     babel-runtime "^6.9.0"
839
-    babel-types "^6.18.0"
840
+    babel-types "^6.19.0"
840 841
     babylon "^6.11.0"
841 842
     debug "^2.2.0"
842 843
     globals "^9.0.0"
843 844
     invariant "^2.2.0"
844 845
     lodash "^4.2.0"
845 846
 
846
-babel-types@^6.0.19, babel-types@^6.16.0, babel-types@^6.18.0, babel-types@^6.8.0, babel-types@^6.9.0:
847
-  version "6.18.0"
848
-  resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.18.0.tgz#1f7d5a73474c59eb9151b2417bbff4e4fce7c3f8"
847
+babel-types@^6.0.19, babel-types@^6.16.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.8.0, babel-types@^6.9.0:
848
+  version "6.19.0"
849
+  resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.19.0.tgz#8db2972dbed01f1192a8b602ba1e1e4c516240b9"
849 850
   dependencies:
850 851
     babel-runtime "^6.9.1"
851 852
     esutils "^2.0.2"
@@ -853,8 +854,8 @@ babel-types@^6.0.19, babel-types@^6.16.0, babel-types@^6.18.0, babel-types@^6.8.
853 854
     to-fast-properties "^1.0.1"
854 855
 
855 856
 babylon@^6.0.18, babylon@^6.11.0, babylon@^6.13.0:
856
-  version "6.13.1"
857
-  resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.13.1.tgz#adca350e088f0467647157652bafead6ddb8dfdb"
857
+  version "6.14.0"
858
+  resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.14.0.tgz#c8ba4b69b544b2cd8f3fb96b06614660a49b7128"
858 859
 
859 860
 balanced-match@^0.4.1:
860 861
   version "0.4.2"
@@ -1641,11 +1642,7 @@ dom-walk@^0.1.0:
1641 1642
   version "0.1.1"
1642 1643
   resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
1643 1644
 
1644
-domelementtype@1:
1645
-  version "1.3.0"
1646
-  resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.3.0.tgz#b17aed82e8ab59e52dd9c19b1756e0fc187204c2"
1647
-
1648
-domelementtype@~1.1.1:
1645
+domelementtype@1, domelementtype@~1.1.1:
1649 1646
   version "1.1.3"
1650 1647
   resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.1.3.tgz#bd28773e2642881aec51544924299c5cd822185b"
1651 1648
 
@@ -2662,11 +2659,11 @@ http-signature@~1.1.0:
2662 2659
     jsprim "^1.2.2"
2663 2660
     sshpk "^1.7.0"
2664 2661
 
2665
-iconv-lite@0.4.11:
2662
+iconv-lite@0.4.11, iconv-lite@^0.4.5:
2666 2663
   version "0.4.11"
2667 2664
   resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.11.tgz#2ecb42fd294744922209a2e7c404dac8793d8ade"
2668 2665
 
2669
-iconv-lite@0.4.13, iconv-lite@^0.4.13, iconv-lite@^0.4.5, iconv-lite@~0.4.13:
2666
+iconv-lite@0.4.13, iconv-lite@^0.4.13, iconv-lite@~0.4.13:
2670 2667
   version "0.4.13"
2671 2668
   resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2"
2672 2669
 
@@ -3198,6 +3195,10 @@ jest-mock@^17.0.2:
3198 3195
   version "17.0.2"
3199 3196
   resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-17.0.2.tgz#3dfe9221afd9aa61b3d9992840813a358bb2f429"
3200 3197
 
3198
+jest-react-native@17.x.x:
3199
+  version "17.0.2"
3200
+  resolved "https://registry.yarnpkg.com/jest-react-native/-/jest-react-native-17.0.2.tgz#de19183cd81ad4560fdaadff84badbdd92ecdf8d"
3201
+
3201 3202
 jest-resolve-dependencies@^17.0.2:
3202 3203
   version "17.0.2"
3203 3204
   resolved "https://registry.yarnpkg.com/jest-resolve-dependencies/-/jest-resolve-dependencies-17.0.2.tgz#585b041b970868ef5192a4874537c6bae040e2cc"
@@ -4386,6 +4387,10 @@ react-proxy@^1.1.7:
4386 4387
     lodash "^4.6.1"
4387 4388
     react-deep-force-update "^1.0.0"
4388 4389
 
4390
+react-test-renderer@15.3.2:
4391
+  version "15.3.2"
4392
+  resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-15.3.2.tgz#d8f083d37d2d41e97bbdc26a1dd9282f0baf7857"
4393
+
4389 4394
 react-timer-mixin@^0.13.2:
4390 4395
   version "0.13.3"
4391 4396
   resolved "https://registry.yarnpkg.com/react-timer-mixin/-/react-timer-mixin-0.13.3.tgz#0da8b9f807ec07dc3e854d082c737c65605b3d22"
@@ -4455,11 +4460,10 @@ readable-stream@1.1, "readable-stream@>=1.1.13-1 <1.2.0-0", readable-stream@^1.1
4455 4460
     isarray "0.0.1"
4456 4461
     string_decoder "~0.10.x"
4457 4462
 
4458
-readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.4, readable-stream@^2.0.5, readable-stream@~2.1.4:
4459
-  version "2.1.5"
4460
-  resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.1.5.tgz#66fa8b720e1438b364681f2ad1a63c618448c9d0"
4463
+readable-stream@^2.0.0, "readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.2, readable-stream@^2.0.4, readable-stream@^2.0.5, readable-stream@~2.0.0, readable-stream@~2.0.5:
4464
+  version "2.0.6"
4465
+  resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.0.6.tgz#8f90341e68a53ccc928788dacfcd11b36eb9b78e"
4461 4466
   dependencies:
4462
-    buffer-shims "^1.0.0"
4463 4467
     core-util-is "~1.0.0"
4464 4468
     inherits "~2.0.1"
4465 4469
     isarray "~1.0.0"
@@ -4467,10 +4471,11 @@ readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.4, readable
4467 4471
     string_decoder "~0.10.x"
4468 4472
     util-deprecate "~1.0.1"
4469 4473
 
4470
-"readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.2, readable-stream@~2.0.0, readable-stream@~2.0.5:
4471
-  version "2.0.6"
4472
-  resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.0.6.tgz#8f90341e68a53ccc928788dacfcd11b36eb9b78e"
4474
+readable-stream@^2.0.1, readable-stream@~2.1.4:
4475
+  version "2.1.5"
4476
+  resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.1.5.tgz#66fa8b720e1438b364681f2ad1a63c618448c9d0"
4473 4477
   dependencies:
4478
+    buffer-shims "^1.0.0"
4474 4479
     core-util-is "~1.0.0"
4475 4480
     inherits "~2.0.1"
4476 4481
     isarray "~1.0.0"