Daniel Zlotin 6 years ago
parent
commit
110eb4394c

+ 16
- 16
lib/src/commands/Commands.js View File

@@ -10,7 +10,7 @@ class Commands {
10 10
 
11 11
   setRoot(simpleApi) {
12 12
     const input = _.cloneDeep(simpleApi);
13
-    const layout = this.layoutTreeParser.parseFromSimpleJSON(input);
13
+    const layout = this.layoutTreeParser.parse(input);
14 14
     this.layoutTreeCrawler.crawl(layout);
15 15
     return this.nativeCommandsSender.setRoot(layout);
16 16
   }
@@ -29,7 +29,7 @@ class Commands {
29 29
 
30 30
   showModal(simpleApi) {
31 31
     const input = _.cloneDeep(simpleApi);
32
-    const layout = this.layoutTreeParser.parseFromSimpleJSON(input);
32
+    const layout = this.layoutTreeParser.parse(input);
33 33
     this.layoutTreeCrawler.crawl(layout);
34 34
     return this.nativeCommandsSender.showModal(layout);
35 35
   }
@@ -45,7 +45,7 @@ class Commands {
45 45
   push(onContainerId, containerData) {
46 46
     const input = _.cloneDeep(containerData);
47 47
     OptionsProcessor.processOptions(input);
48
-    const layout = this.layoutTreeParser.parseFromSimpleJSON(input);
48
+    const layout = this.layoutTreeParser.parse(input);
49 49
     this.layoutTreeCrawler.crawl(layout);
50 50
     return this.nativeCommandsSender.push(onContainerId, layout);
51 51
   }
@@ -62,19 +62,19 @@ class Commands {
62 62
     return this.nativeCommandsSender.popToRoot(containerId);
63 63
   }
64 64
 
65
-  showOverlay(type, options) {
66
-    let promise;
67
-    if (type === 'custom') {
68
-      const layout = this.layoutTreeParser.createDialogContainer({ name: options });
69
-      this.layoutTreeCrawler.crawl(layout);
70
-      promise = this.nativeCommandsSender.showOverlay(type, layout);
71
-    } else {
72
-      const input = _.cloneDeep(options);
73
-      OptionsProcessor.processOptions(input);
74
-      promise = this.nativeCommandsSender.showOverlay(type, input);
75
-    }
76
-    return promise;
77
-  }
65
+  // showOverlay(type, options) {
66
+    // let promise;
67
+    // if (type === 'custom') {
68
+    //   const layout = this.layoutTreeParser.createDialogContainer({ name: options });
69
+    //   this.layoutTreeCrawler.crawl(layout);
70
+    //   promise = this.nativeCommandsSender.showOverlay(type, layout);
71
+    // } else {
72
+    //   const input = _.cloneDeep(options);
73
+    //   OptionsProcessor.processOptions(input);
74
+    //   promise = this.nativeCommandsSender.showOverlay(type, input);
75
+    // }
76
+    // return promise;
77
+  // }
78 78
 
79 79
   dismissOverlay() {
80 80
     return this.nativeCommandsSender.dismissOverlay();

+ 44
- 48
lib/src/commands/Commands.test.js View File

@@ -20,44 +20,41 @@ describe('Commands', () => {
20 20
   describe('setRoot', () => {
21 21
     it('sends setRoot to native after parsing into a correct layout tree', () => {
22 22
       uut.setRoot({
23
-        container: {
23
+        component: {
24 24
           name: 'com.example.MyScreen'
25 25
         }
26 26
       });
27 27
       expect(mockCommandsSender.setRoot).toHaveBeenCalledTimes(1);
28 28
       expect(mockCommandsSender.setRoot).toHaveBeenCalledWith({
29
-        type: 'ContainerStack',
30
-        id: 'ContainerStack+UNIQUE_ID',
31
-        data: {},
32
-        children: [
33
-          {
34
-            type: 'Container',
35
-            id: 'Container+UNIQUE_ID',
36
-            children: [],
37
-            data: {
38
-              name: 'com.example.MyScreen',
39
-              navigationOptions: {}
40
-            }
41
-          }
42
-        ]
29
+        type: 'Component',
30
+        id: 'Component+UNIQUE_ID',
31
+        children: [],
32
+        data: {
33
+          name: 'com.example.MyScreen',
34
+          navigationOptions: {}
35
+        }
43 36
       });
44 37
     });
45 38
 
46 39
     it('deep clones input to avoid mutation errors', () => {
47 40
       const obj = {};
48
-      uut.setRoot({ container: { name: 'bla', inner: obj } });
49
-      expect(mockCommandsSender.setRoot.mock.calls[0][0].children[0].data.inner).not.toBe(obj);
41
+      uut.setRoot({ component: { name: 'bla', inner: obj } });
42
+      expect(mockCommandsSender.setRoot.mock.calls[0][0].data.inner).not.toBe(obj);
50 43
     });
51 44
 
52 45
     it('passProps into containers', () => {
53
-      expect(store.getPropsForContainerId('Container+UNIQUE_ID')).toEqual({});
54
-      uut.setRoot(SimpleLayouts.singleScreenWithAditionalParams);
55
-      expect(store.getPropsForContainerId('Container+UNIQUE_ID')).toEqual(SimpleLayouts.passProps);
46
+      const passProps = {
47
+        fn: () => 'Hello'
48
+      };
49
+      expect(store.getPropsForContainerId('Component+UNIQUE_ID')).toEqual({});
50
+      uut.setRoot({ component: { name: 'asd', passProps } });
51
+      expect(store.getPropsForContainerId('Component+UNIQUE_ID')).toEqual(passProps);
52
+      expect(store.getPropsForContainerId('Component+UNIQUE_ID').fn()).toEqual('Hello');
56 53
     });
57 54
 
58 55
     it('returns a promise with the resolved layout', async () => {
59 56
       mockCommandsSender.setRoot.mockReturnValue(Promise.resolve('the resolved layout'));
60
-      const result = await uut.setRoot({ container: { name: 'com.example.MyScreen' } });
57
+      const result = await uut.setRoot({ component: { name: 'com.example.MyScreen' } });
61 58
       expect(result).toEqual('the resolved layout');
62 59
     });
63 60
   });
@@ -87,47 +84,45 @@ describe('Commands', () => {
87 84
   describe('showModal', () => {
88 85
     it('sends command to native after parsing into a correct layout tree', () => {
89 86
       uut.showModal({
90
-        container: {
87
+        component: {
91 88
           name: 'com.example.MyScreen'
92 89
         }
93 90
       });
94 91
       expect(mockCommandsSender.showModal).toHaveBeenCalledTimes(1);
95 92
       expect(mockCommandsSender.showModal).toHaveBeenCalledWith({
96
-        type: 'ContainerStack',
97
-        id: 'ContainerStack+UNIQUE_ID',
98
-        data: {},
99
-        children: [{
100
-          type: 'Container',
101
-          id: 'Container+UNIQUE_ID',
102
-          data: {
103
-            name: 'com.example.MyScreen',
104
-            navigationOptions: {}
105
-          },
106
-          children: []
107
-        }]
93
+        type: 'Component',
94
+        id: 'Component+UNIQUE_ID',
95
+        data: {
96
+          name: 'com.example.MyScreen',
97
+          navigationOptions: {}
98
+        },
99
+        children: []
108 100
       });
109 101
     });
110 102
 
111 103
     it('deep clones input to avoid mutation errors', () => {
112 104
       const obj = {};
113
-      uut.showModal({ container: { name: 'name', inner: obj } });
105
+      uut.showModal({ component: { name: 'name', inner: obj } });
114 106
       expect(mockCommandsSender.showModal.mock.calls[0][0].data.inner).not.toBe(obj);
115 107
     });
116 108
 
117 109
     it('passProps into containers', () => {
118
-      expect(store.getPropsForContainerId('Container+UNIQUE_ID')).toEqual({});
110
+      const passProps = {
111
+        fn: () => 'hello'
112
+      };
113
+      expect(store.getPropsForContainerId('Component+UNIQUE_ID')).toEqual({});
119 114
       uut.showModal({
120
-        container: {
115
+        component: {
121 116
           name: 'com.example.MyScreen',
122
-          passProps: SimpleLayouts.passProps
117
+          passProps
123 118
         }
124 119
       });
125
-      expect(store.getPropsForContainerId('Container+UNIQUE_ID')).toEqual(SimpleLayouts.passProps);
120
+      expect(store.getPropsForContainerId('Component+UNIQUE_ID')).toEqual(passProps);
126 121
     });
127 122
 
128 123
     it('returns a promise with the resolved layout', async () => {
129 124
       mockCommandsSender.showModal.mockReturnValue(Promise.resolve('the resolved layout'));
130
-      const result = await uut.showModal({ container: { name: 'com.example.MyScreen' } });
125
+      const result = await uut.showModal({ component: { name: 'com.example.MyScreen' } });
131 126
       expect(result).toEqual('the resolved layout');
132 127
     });
133 128
   });
@@ -163,22 +158,22 @@ describe('Commands', () => {
163 158
   describe('push', () => {
164 159
     it('deep clones input to avoid mutation errors', () => {
165 160
       const obj = {};
166
-      uut.push('theContainerId', { name: 'name', inner: { foo: obj } });
167
-      expect(mockCommandsSender.push.mock.calls[0][1].data.inner.foo).not.toBe(obj);
161
+      uut.push('theContainerId', { component: { name: 'name', passProps: { foo: obj } } });
162
+      expect(mockCommandsSender.push.mock.calls[0][1].data.passProps.foo).not.toBe(obj);
168 163
     });
169 164
 
170 165
     it('resolves with the parsed layout', async () => {
171 166
       mockCommandsSender.push.mockReturnValue(Promise.resolve('the resolved layout'));
172
-      const result = await uut.push('theContainerId', { name: 'com.example.MyScreen' });
167
+      const result = await uut.push('theContainerId', { component: { name: 'com.example.MyScreen' } });
173 168
       expect(result).toEqual('the resolved layout');
174 169
     });
175 170
 
176 171
     it('parses into correct layout node and sends to native', () => {
177
-      uut.push('theContainerId', { name: 'com.example.MyScreen' });
172
+      uut.push('theContainerId', { component: { name: 'com.example.MyScreen' } });
178 173
       expect(mockCommandsSender.push).toHaveBeenCalledTimes(1);
179 174
       expect(mockCommandsSender.push).toHaveBeenCalledWith('theContainerId', {
180
-        type: 'Container',
181
-        id: 'Container+UNIQUE_ID',
175
+        type: 'Component',
176
+        id: 'Component+UNIQUE_ID',
182 177
         data: {
183 178
           name: 'com.example.MyScreen',
184 179
           navigationOptions: {}
@@ -201,7 +196,8 @@ describe('Commands', () => {
201 196
             { type: 'sharedElement', fromId: 'title2', toId: 'title1', startDelay: 0, springVelocity: 0.2, duration: 0.5 }
202 197
           ],
203 198
           duration: 0.8
204
-        } };
199
+        }
200
+      };
205 201
       uut.pop('theContainerId', options);
206 202
       expect(mockCommandsSender.pop).toHaveBeenCalledTimes(1);
207 203
       expect(mockCommandsSender.pop).toHaveBeenCalledWith('theContainerId', options);
@@ -242,7 +238,7 @@ describe('Commands', () => {
242 238
     });
243 239
   });
244 240
 
245
-  describe('showOverlay', () => {
241
+  xdescribe('showOverlay', () => {
246 242
     it('deep clones input to avoid mutation errors', () => {
247 243
       const obj = { title: 'test' };
248 244
       uut.showOverlay('alert', obj);

+ 1
- 1
lib/src/commands/LayoutTreeCrawler.js View File

@@ -14,7 +14,7 @@ class LayoutTreeCrawler {
14 14
     node.id = this.uniqueIdProvider.generate(node.type);
15 15
     node.data = node.data || {};
16 16
     node.children = node.children || [];
17
-    if ([LayoutTypes.Container, LayoutTypes.TopTab].includes(node.type)) {
17
+    if (_.isEqual(node.type, LayoutTypes.Component)) {
18 18
       this._handleContainer(node);
19 19
     }
20 20
     _.forEach(node.children, this.crawl);

+ 16
- 16
lib/src/commands/LayoutTreeCrawler.test.js View File

@@ -13,38 +13,38 @@ describe('LayoutTreeCrawler', () => {
13 13
   });
14 14
 
15 15
   it('crawls a layout tree and adds unique id to each node', () => {
16
-    const node = { type: LayoutTypes.ContainerStack, children: [{ type: LayoutTypes.BottomTabs }] };
16
+    const node = { type: LayoutTypes.Stack, children: [{ type: LayoutTypes.BottomTabs }] };
17 17
     uut.crawl(node);
18
-    expect(node.id).toEqual('ContainerStack+UNIQUE_ID');
18
+    expect(node.id).toEqual('Stack+UNIQUE_ID');
19 19
     expect(node.children[0].id).toEqual('BottomTabs+UNIQUE_ID');
20 20
   });
21 21
 
22 22
   it('crawls a layout tree and ensures data exists', () => {
23
-    const node = { type: LayoutTypes.ContainerStack, children: [{ type: LayoutTypes.BottomTabs }] };
23
+    const node = { type: LayoutTypes.Stack, children: [{ type: LayoutTypes.BottomTabs }] };
24 24
     uut.crawl(node);
25 25
     expect(node.data).toEqual({});
26 26
     expect(node.children[0].data).toEqual({});
27 27
   });
28 28
 
29 29
   it('crawls a layout tree and ensures children exists', () => {
30
-    const node = { type: LayoutTypes.ContainerStack, children: [{ type: LayoutTypes.BottomTabs }] };
30
+    const node = { type: LayoutTypes.Stack, children: [{ type: LayoutTypes.BottomTabs }] };
31 31
     uut.crawl(node);
32 32
     expect(node.children[0].children).toEqual([]);
33 33
   });
34 34
 
35 35
   it('crawls a layout tree and asserts known layout type', () => {
36
-    const node = { type: LayoutTypes.ContainerStack, children: [{ type: 'Bob' }] };
36
+    const node = { type: LayoutTypes.Stack, children: [{ type: 'Bob' }] };
37 37
     expect(() => uut.crawl(node)).toThrow(new Error('Unknown layout type Bob'));
38 38
   });
39 39
 
40
-  it('saves passProps into store for Container nodes', () => {
40
+  it('saves passProps into store for Component nodes', () => {
41 41
     const node = {
42 42
       type: LayoutTypes.BottomTabs, children: [
43
-        { type: LayoutTypes.Container, data: { name: 'the name', passProps: { myProp: 123 } } }]
43
+        { type: LayoutTypes.Component, data: { name: 'the name', passProps: { myProp: 123 } } }]
44 44
     };
45
-    expect(store.getPropsForContainerId('Container+UNIQUE_ID')).toEqual({});
45
+    expect(store.getPropsForContainerId('Component+UNIQUE_ID')).toEqual({});
46 46
     uut.crawl(node);
47
-    expect(store.getPropsForContainerId('Container+UNIQUE_ID')).toEqual({ myProp: 123 });
47
+    expect(store.getPropsForContainerId('Component+UNIQUE_ID')).toEqual({ myProp: 123 });
48 48
   });
49 49
 
50 50
   it('Containers: injects navigationOptions from original container class static property', () => {
@@ -55,7 +55,7 @@ describe('LayoutTreeCrawler', () => {
55 55
       }
56 56
     };
57 57
 
58
-    const node = { type: LayoutTypes.Container, data: { name: 'theContainerName' } };
58
+    const node = { type: LayoutTypes.Component, data: { name: 'theContainerName' } };
59 59
     store.setOriginalContainerClassForName('theContainerName', MyContainer);
60 60
     uut.crawl(node);
61 61
     expect(node.data.navigationOptions).toEqual(theStyle);
@@ -83,7 +83,7 @@ describe('LayoutTreeCrawler', () => {
83 83
       }
84 84
     };
85 85
 
86
-    const node = { type: LayoutTypes.Container, data: { name: 'theContainerName', navigationOptions: passedOptions } };
86
+    const node = { type: LayoutTypes.Component, data: { name: 'theContainerName', navigationOptions: passedOptions } };
87 87
     store.setOriginalContainerClassForName('theContainerName', MyContainer);
88 88
 
89 89
     uut.crawl(node);
@@ -98,7 +98,7 @@ describe('LayoutTreeCrawler', () => {
98 98
     });
99 99
   });
100 100
 
101
-  it('Containers: deepClones navigationOptions', () => {
101
+  it('Component: deepClones navigationOptions', () => {
102 102
     const theStyle = {};
103 103
     const MyContainer = class {
104 104
       static get navigationOptions() {
@@ -106,21 +106,21 @@ describe('LayoutTreeCrawler', () => {
106 106
       }
107 107
     };
108 108
 
109
-    const node = { type: LayoutTypes.Container, data: { name: 'theContainerName' } };
109
+    const node = { type: LayoutTypes.Component, data: { name: 'theContainerName' } };
110 110
     store.setOriginalContainerClassForName('theContainerName', MyContainer);
111 111
     uut.crawl(node);
112 112
     expect(node.data.navigationOptions).not.toBe(theStyle);
113 113
   });
114 114
 
115 115
   it('Containers: must contain data name', () => {
116
-    const node = { type: LayoutTypes.Container, data: {} };
116
+    const node = { type: LayoutTypes.Component, data: {} };
117 117
     expect(() => uut.crawl(node)).toThrow(new Error('Missing container data.name'));
118 118
   });
119 119
 
120 120
   it('Containers: navigationOptions default obj', () => {
121 121
     const MyContainer = class { };
122 122
 
123
-    const node = { type: LayoutTypes.Container, data: { name: 'theContainerName' } };
123
+    const node = { type: LayoutTypes.Component, data: { name: 'theContainerName' } };
124 124
     store.setOriginalContainerClassForName('theContainerName', MyContainer);
125 125
     uut.crawl(node);
126 126
     expect(node.data.navigationOptions).toEqual({});
@@ -132,7 +132,7 @@ describe('LayoutTreeCrawler', () => {
132 132
 
133 133
     beforeEach(() => {
134 134
       navigationOptions = {};
135
-      node = { type: LayoutTypes.Container, data: { name: 'theContainerName', navigationOptions } };
135
+      node = { type: LayoutTypes.Component, data: { name: 'theContainerName', navigationOptions } };
136 136
     });
137 137
 
138 138
     it('processes colors into numeric AARRGGBB', () => {