Sfoglia il codice sorgente

this doesnt quite work

Daniel Zlotin 7 anni fa
parent
commit
5e00c1838d

lib/src/commands/Commands.test.js → lib/src/commands/Commands.test.ts Vedi File

1
-const LayoutTreeParser = require('./LayoutTreeParser');
2
-const LayoutTreeCrawler = require('./LayoutTreeCrawler');
3
-const Store = require('../components/Store');
4
-const { UniqueIdProvider } = require('../adapters/UniqueIdProvider.mock');
5
-const { NativeCommandsSender } = require('../adapters/NativeCommandsSender.mock');
6
-const Commands = require('./Commands');
1
+import { LayoutTreeParser } from './LayoutTreeParser';
2
+import { LayoutTreeCrawler } from './LayoutTreeCrawler';
3
+import { Store } from '../components/Store';
4
+import { UniqueIdProvider } from '../adapters/UniqueIdProvider.mock';
5
+import { NativeCommandsSender } from '../adapters/NativeCommandsSender.mock';
6
+import { Commands } from './Commands';
7
 
7
 
8
 describe('Commands', () => {
8
 describe('Commands', () => {
9
   let uut;
9
   let uut;

lib/src/commands/Commands.js → lib/src/commands/Commands.ts Vedi File

1
-const _ = require('lodash');
2
-const OptionsProcessor = require('./OptionsProcessor');
1
+import * as _ from 'lodash';
2
+import { OptionsProcessor } from './OptionsProcessor';
3
+
4
+export class Commands {
5
+  private nativeCommandsSender: any;
6
+  private layoutTreeParser: any;
7
+  private layoutTreeCrawler: any;
3
 
8
 
4
-class Commands {
5
   constructor(nativeCommandsSender, layoutTreeParser, layoutTreeCrawler) {
9
   constructor(nativeCommandsSender, layoutTreeParser, layoutTreeCrawler) {
6
     this.nativeCommandsSender = nativeCommandsSender;
10
     this.nativeCommandsSender = nativeCommandsSender;
7
     this.layoutTreeParser = layoutTreeParser;
11
     this.layoutTreeParser = layoutTreeParser;
8
     this.layoutTreeCrawler = layoutTreeCrawler;
12
     this.layoutTreeCrawler = layoutTreeCrawler;
9
   }
13
   }
10
 
14
 
11
-  setRoot(simpleApi) {
15
+  setRoot(simpleApi: any) {
12
     const input = _.cloneDeep(simpleApi);
16
     const input = _.cloneDeep(simpleApi);
13
     const layout = this.layoutTreeParser.parse(input);
17
     const layout = this.layoutTreeParser.parse(input);
14
     this.layoutTreeCrawler.crawl(layout);
18
     this.layoutTreeCrawler.crawl(layout);
63
   }
67
   }
64
 
68
 
65
   // showOverlay(type, options) {
69
   // showOverlay(type, options) {
66
-    // let promise;
67
-    // if (type === 'custom') {
68
-    //   const layout = this.layoutTreeParser.createDialogComponent({ 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;
70
+  // let promise;
71
+  // if (type === 'custom') {
72
+  //   const layout = this.layoutTreeParser.createDialogComponent({ name: options });
73
+  //   this.layoutTreeCrawler.crawl(layout);
74
+  //   promise = this.nativeCommandsSender.showOverlay(type, layout);
75
+  // } else {
76
+  //   const input = _.cloneDeep(options);
77
+  //   OptionsProcessor.processOptions(input);
78
+  //   promise = this.nativeCommandsSender.showOverlay(type, input);
79
+  // }
80
+  // return promise;
77
   // }
81
   // }
78
 
82
 
79
   dismissOverlay() {
83
   dismissOverlay() {
80
     return this.nativeCommandsSender.dismissOverlay();
84
     return this.nativeCommandsSender.dismissOverlay();
81
   }
85
   }
82
 }
86
 }
83
-
84
-module.exports = Commands;

lib/src/commands/LayoutTreeCrawler.test.js → lib/src/commands/LayoutTreeCrawler.test.ts Vedi File

1
-const LayoutTypes = require('./LayoutTypes');
2
-const LayoutTreeCrawler = require('./LayoutTreeCrawler');
1
+import { LayoutType } from './values/LayoutType';
2
+import { LayoutTreeCrawler } from './LayoutTreeCrawler';
3
+import { UniqueIdProvider } from '../adapters/UniqueIdProvider.mock';
4
+import { LayoutNode } from './values/LayoutNode';
3
 const Store = require('../components/Store');
5
 const Store = require('../components/Store');
4
-const UniqueIdProvider = require('../adapters/UniqueIdProvider.mock');
5
 
6
 
6
 describe('LayoutTreeCrawler', () => {
7
 describe('LayoutTreeCrawler', () => {
7
   let uut;
8
   let uut;
13
   });
14
   });
14
 
15
 
15
   it('crawls a layout tree and adds unique id to each node', () => {
16
   it('crawls a layout tree and adds unique id to each node', () => {
16
-    const node = { type: LayoutTypes.Stack, children: [{ type: LayoutTypes.BottomTabs }] };
17
+    const node: any = { type: LayoutType.Stack, children: [{ type: LayoutType.BottomTabs }] };
17
     uut.crawl(node);
18
     uut.crawl(node);
18
     expect(node.id).toEqual('Stack+UNIQUE_ID');
19
     expect(node.id).toEqual('Stack+UNIQUE_ID');
19
     expect(node.children[0].id).toEqual('BottomTabs+UNIQUE_ID');
20
     expect(node.children[0].id).toEqual('BottomTabs+UNIQUE_ID');
20
   });
21
   });
21
 
22
 
22
   it('crawls a layout tree and ensures data exists', () => {
23
   it('crawls a layout tree and ensures data exists', () => {
23
-    const node = { type: LayoutTypes.Stack, children: [{ type: LayoutTypes.BottomTabs }] };
24
+    const node: any = { type: LayoutType.Stack, children: [{ type: LayoutType.BottomTabs }] };
24
     uut.crawl(node);
25
     uut.crawl(node);
25
     expect(node.data).toEqual({});
26
     expect(node.data).toEqual({});
26
     expect(node.children[0].data).toEqual({});
27
     expect(node.children[0].data).toEqual({});
27
   });
28
   });
28
 
29
 
29
   it('crawls a layout tree and ensures children exists', () => {
30
   it('crawls a layout tree and ensures children exists', () => {
30
-    const node = { type: LayoutTypes.Stack, children: [{ type: LayoutTypes.BottomTabs }] };
31
+    const node: any = { type: LayoutType.Stack, children: [{ type: LayoutType.BottomTabs }] };
31
     uut.crawl(node);
32
     uut.crawl(node);
32
     expect(node.children[0].children).toEqual([]);
33
     expect(node.children[0].children).toEqual([]);
33
   });
34
   });
34
 
35
 
35
   it('crawls a layout tree and asserts known layout type', () => {
36
   it('crawls a layout tree and asserts known layout type', () => {
36
-    const node = { type: LayoutTypes.Stack, children: [{ type: 'Bob' }] };
37
-    expect(() => uut.crawl(node)).toThrow(new Error('Unknown layout type Bob'));
37
+    const node = { type: LayoutType.Stack, children: [{ type: 'Bob' }] };
38
+    expect(() => uut.crawl(node)).toThrowError('Unknown layout type Bob');
38
   });
39
   });
39
 
40
 
40
   it('saves passProps into store for Component nodes', () => {
41
   it('saves passProps into store for Component nodes', () => {
41
     const node = {
42
     const node = {
42
-      type: LayoutTypes.BottomTabs, children: [
43
-        { type: LayoutTypes.Component, data: { name: 'the name', passProps: { myProp: 123 } } }]
43
+      type: LayoutType.BottomTabs, children: [
44
+        { type: LayoutType.Component, data: { name: 'the name', passProps: { myProp: 123 } } }]
44
     };
45
     };
45
     expect(store.getPropsForComponentId('Component+UNIQUE_ID')).toEqual({});
46
     expect(store.getPropsForComponentId('Component+UNIQUE_ID')).toEqual({});
46
     uut.crawl(node);
47
     uut.crawl(node);
55
       }
56
       }
56
     };
57
     };
57
 
58
 
58
-    const node = { type: LayoutTypes.Component, data: { name: 'theComponentName' } };
59
+    const node: any = { type: LayoutType.Component, data: { name: 'theComponentName' } };
59
     store.setOriginalComponentClassForName('theComponentName', MyComponent);
60
     store.setOriginalComponentClassForName('theComponentName', MyComponent);
60
     uut.crawl(node);
61
     uut.crawl(node);
61
     expect(node.data.options).toEqual(theStyle);
62
     expect(node.data.options).toEqual(theStyle);
83
       }
84
       }
84
     };
85
     };
85
 
86
 
86
-    const node = { type: LayoutTypes.Component, data: { name: 'theComponentName', options: passedOptions } };
87
+    const node = { type: LayoutType.Component, data: { name: 'theComponentName', options: passedOptions } };
87
     store.setOriginalComponentClassForName('theComponentName', MyComponent);
88
     store.setOriginalComponentClassForName('theComponentName', MyComponent);
88
 
89
 
89
     uut.crawl(node);
90
     uut.crawl(node);
106
       }
107
       }
107
     };
108
     };
108
 
109
 
109
-    const node = { type: LayoutTypes.Component, data: { name: 'theComponentName' } };
110
+    const node: any = { type: LayoutType.Component, data: { name: 'theComponentName' } };
110
     store.setOriginalComponentClassForName('theComponentName', MyComponent);
111
     store.setOriginalComponentClassForName('theComponentName', MyComponent);
111
     uut.crawl(node);
112
     uut.crawl(node);
112
     expect(node.data.options).not.toBe(theStyle);
113
     expect(node.data.options).not.toBe(theStyle);
113
   });
114
   });
114
 
115
 
115
   it('Components: must contain data name', () => {
116
   it('Components: must contain data name', () => {
116
-    const node = { type: LayoutTypes.Component, data: {} };
117
-    expect(() => uut.crawl(node)).toThrow(new Error('Missing component data.name'));
117
+    const node = { type: LayoutType.Component, data: {} };
118
+    expect(() => uut.crawl(node)).toThrowError('Missing component data.name');
118
   });
119
   });
119
 
120
 
120
   it('Components: options default obj', () => {
121
   it('Components: options default obj', () => {
121
     const MyComponent = class { };
122
     const MyComponent = class { };
122
 
123
 
123
-    const node = { type: LayoutTypes.Component, data: { name: 'theComponentName' } };
124
+    const node: any = { type: LayoutType.Component, data: { name: 'theComponentName' } };
124
     store.setOriginalComponentClassForName('theComponentName', MyComponent);
125
     store.setOriginalComponentClassForName('theComponentName', MyComponent);
125
     uut.crawl(node);
126
     uut.crawl(node);
126
     expect(node.data.options).toEqual({});
127
     expect(node.data.options).toEqual({});
132
 
133
 
133
     beforeEach(() => {
134
     beforeEach(() => {
134
       options = {};
135
       options = {};
135
-      node = { type: LayoutTypes.Component, data: { name: 'theComponentName', options } };
136
+      node = { type: LayoutType.Component, data: { name: 'theComponentName', options } };
136
     });
137
     });
137
 
138
 
138
     it('processes colors into numeric AARRGGBB', () => {
139
     it('processes colors into numeric AARRGGBB', () => {

lib/src/commands/LayoutTreeCrawler.js → lib/src/commands/LayoutTreeCrawler.ts Vedi File

1
-import { LayoutTypes } from './LayoutTypes';
1
+import * as _ from 'lodash';
2
+import { OptionsProcessor } from './OptionsProcessor';
3
+import { LayoutType, isLayoutType } from './values/LayoutType';
4
+import { LayoutNode } from './values/LayoutNode';
2
 
5
 
3
-const _ = require('lodash');
4
-const OptionsProcessor = require('./OptionsProcessor');
6
+interface IdProvider {
7
+  generate: (str: string) => string;
8
+}
9
+
10
+interface Store {
11
+  setPropsForComponentId: (str: string, props: object) => void;
12
+  getOriginalComponentClassForName: (str: string) => any;
13
+}
5
 
14
 
6
-class LayoutTreeCrawler {
7
-  constructor(uniqueIdProvider, store) {
15
+export class LayoutTreeCrawler {
16
+  private uniqueIdProvider: IdProvider
17
+  private store: Store
18
+
19
+  constructor(uniqueIdProvider: IdProvider, store: Store) {
8
     this.uniqueIdProvider = uniqueIdProvider;
20
     this.uniqueIdProvider = uniqueIdProvider;
9
     this.store = store;
21
     this.store = store;
10
     this.crawl = this.crawl.bind(this);
22
     this.crawl = this.crawl.bind(this);
11
   }
23
   }
12
 
24
 
13
-  crawl(node) {
25
+  crawl(node: LayoutNode): void {
14
     this._assertKnownLayoutType(node.type);
26
     this._assertKnownLayoutType(node.type);
15
     node.id = this.uniqueIdProvider.generate(node.type);
27
     node.id = this.uniqueIdProvider.generate(node.type);
16
     node.data = node.data || {};
28
     node.data = node.data || {};
17
     node.children = node.children || [];
29
     node.children = node.children || [];
18
-    if (_.isEqual(node.type, LayoutTypes.Component)) {
30
+    if (node.type == LayoutType.Component) {
19
       this._handleComponent(node);
31
       this._handleComponent(node);
20
     }
32
     }
21
     _.forEach(node.children, this.crawl);
33
     _.forEach(node.children, this.crawl);
40
   }
52
   }
41
 
53
 
42
   _assertKnownLayoutType(type) {
54
   _assertKnownLayoutType(type) {
43
-    if (!_.includes(LayoutTypes, type)) {
55
+    if (!isLayoutType(type)) {
44
       throw new Error(`Unknown layout type ${type}`);
56
       throw new Error(`Unknown layout type ${type}`);
45
     }
57
     }
46
   }
58
   }
51
     }
63
     }
52
   }
64
   }
53
 }
65
 }
54
-
55
-module.exports = LayoutTreeCrawler;

+ 113
- 103
lib/src/commands/LayoutTreeParser.test.ts Vedi File

11
 
11
 
12
   describe('parses into { type, data, children }', () => {
12
   describe('parses into { type, data, children }', () => {
13
     it('unknown type', () => {
13
     it('unknown type', () => {
14
-      expect(() => uut.parse({ wut: {} })).toThrow(new Error('unknown LayoutType "wut"'));
14
+      expect(() => uut.parse({ wut: {} })).toThrowError('unknown LayoutType "wut"');
15
     });
15
     });
16
 
16
 
17
     it('single component', () => {
17
     it('single component', () => {
88
     });
88
     });
89
 
89
 
90
     it('side menu center is require', () => {
90
     it('side menu center is require', () => {
91
-      expect(() => uut.parse({ sideMenu: {} })).toThrow(new Error('sideMenu.center is required'));
91
+      expect(() => uut.parse({ sideMenu: {} })).toThrowError('sideMenu.center is required');
92
     });
92
     });
93
 
93
 
94
     it('top tabs', () => {
94
     it('top tabs', () => {
127
   });
127
   });
128
 });
128
 });
129
 
129
 
130
-const LayoutExamples = {
131
-  passProps: {
132
-    strProp: 'string prop',
133
-    numProp: 12345,
134
-    objProp: { inner: { foo: 'bar' } },
135
-    fnProp: () => 'Hello from a function'
136
-  },
137
-
138
-  options: {
139
-    topBar: {
140
-      title: 'Hello1'
141
-    }
142
-  },
130
+/* Layout Examples: */
143
 
131
 
144
-  singleComponent: {
145
-    component: {
146
-      name: 'MyReactComponent',
147
-      options: this.options,
148
-      passProps: this.passProps
149
-    }
150
-  },
151
-
152
-  stackWithTopBar: {
153
-    stack: {
154
-      children: [
155
-        {
156
-          component: {
157
-            name: 'MyReactComponent1'
158
-          }
159
-        },
160
-        {
161
-          component: {
162
-            name: 'MyReactComponent2',
163
-            options: this.options
164
-          }
132
+const passProps = {
133
+  strProp: 'string prop',
134
+  numProp: 12345,
135
+  objProp: { inner: { foo: 'bar' } },
136
+  fnProp: () => 'Hello from a function'
137
+};
138
+
139
+const options = {
140
+  topBar: {
141
+    title: 'Hello1'
142
+  }
143
+};
144
+
145
+const singleComponent = {
146
+  component: {
147
+    name: 'MyReactComponent',
148
+    options,
149
+    passProps
150
+  }
151
+};
152
+
153
+const stackWithTopBar = {
154
+  stack: {
155
+    children: [
156
+      {
157
+        component: {
158
+          name: 'MyReactComponent1'
165
         }
159
         }
166
-      ],
167
-      options: this.options
168
-    }
169
-  },
160
+      },
161
+      {
162
+        component: {
163
+          name: 'MyReactComponent2',
164
+          options
165
+        }
166
+      }
167
+    ],
168
+    options
169
+  }
170
+};
170
 
171
 
172
+const bottomTabs = {
171
   bottomTabs: {
173
   bottomTabs: {
172
-    bottomTabs: {
173
-      children: [
174
-        { ...this.stackWithTopBar },
175
-        { ...this.stackWithTopBar },
176
-        {
177
-          component: {
178
-            name: 'MyReactComponent1'
179
-          }
174
+    children: [
175
+      stackWithTopBar,
176
+      stackWithTopBar,
177
+      {
178
+        component: {
179
+          name: 'MyReactComponent1'
180
         }
180
         }
181
-      ]
182
-    }
183
-  },
181
+      }
182
+    ]
183
+  }
184
+};
184
 
185
 
186
+const sideMenu = {
185
   sideMenu: {
187
   sideMenu: {
186
-    sideMenu: {
187
-      left: { ...this.singleComponent },
188
-      center: { ...this.stackWithTopBar },
189
-      right: { ...this.singleComponent }
190
-    }
191
-  },
188
+    left: singleComponent,
189
+    center: stackWithTopBar,
190
+    right: singleComponent
191
+  }
192
+};
192
 
193
 
194
+const topTabs = {
193
   topTabs: {
195
   topTabs: {
194
-    topTabs: {
195
-      children: [
196
-        { ...this.singleComponent },
197
-        { ...this.singleComponent },
198
-        { ...this.singleComponent },
199
-        { ...this.singleComponent },
200
-        { ...this.stackWithTopBar }
201
-      ],
202
-      options: this.options
203
-    }
204
-  },
205
-
206
-  complexLayout: {
207
-    sideMenu: {
208
-      left: { ...this.singleComponent },
209
-      center: {
210
-        bottomTabs: {
211
-          children: [
212
-            { ...this.stackWithTopBar },
213
-            { ...this.stackWithTopBar },
214
-            {
215
-              stack: {
216
-                children: [
217
-                  {
218
-                    topTabs: {
219
-                      children: [
220
-                        { ...this.stackWithTopBar },
221
-                        { ...this.stackWithTopBar },
222
-                        {
223
-                          topTabs: {
224
-                            options: this.options,
225
-                            children: [
226
-                              { ...this.singleComponent },
227
-                              { ...this.singleComponent },
228
-                              { ...this.singleComponent },
229
-                              { ...this.singleComponent },
230
-                              { ...this.stackWithTopBar }
231
-                            ]
232
-                          }
196
+    children: [
197
+      singleComponent,
198
+      singleComponent,
199
+      singleComponent,
200
+      singleComponent,
201
+      stackWithTopBar
202
+    ],
203
+    options
204
+  }
205
+};
206
+
207
+const complexLayout = {
208
+  sideMenu: {
209
+    left: singleComponent,
210
+    center: {
211
+      bottomTabs: {
212
+        children: [
213
+          stackWithTopBar,
214
+          stackWithTopBar,
215
+          {
216
+            stack: {
217
+              children: [
218
+                {
219
+                  topTabs: {
220
+                    children: [
221
+                      stackWithTopBar,
222
+                      stackWithTopBar,
223
+                      {
224
+                        topTabs: {
225
+                          options,
226
+                          children: [
227
+                            singleComponent,
228
+                            singleComponent,
229
+                            singleComponent,
230
+                            singleComponent,
231
+                            stackWithTopBar
232
+                          ]
233
                         }
233
                         }
234
-                      ]
235
-                    }
234
+                      }
235
+                    ]
236
                   }
236
                   }
237
-                ]
238
-              }
237
+                }
238
+              ]
239
             }
239
             }
240
-          ]
241
-        }
240
+          }
241
+        ]
242
       }
242
       }
243
     }
243
     }
244
   }
244
   }
245
-}
245
+};
246
 
246
 
247
+const LayoutExamples = {
248
+  passProps,
249
+  options,
250
+  singleComponent,
251
+  stackWithTopBar,
252
+  bottomTabs,
253
+  sideMenu,
254
+  topTabs,
255
+  complexLayout
256
+};

+ 8
- 10
lib/src/commands/LayoutTreeParser.ts Vedi File

1
 import * as _ from 'lodash';
1
 import * as _ from 'lodash';
2
 import { LayoutType } from './values/LayoutType';
2
 import { LayoutType } from './values/LayoutType';
3
+import { LayoutNode } from './values/LayoutNode';
3
 
4
 
4
 export class LayoutTreeParser {
5
 export class LayoutTreeParser {
5
   constructor() {
6
   constructor() {
6
     this.parse = this.parse.bind(this);
7
     this.parse = this.parse.bind(this);
7
   }
8
   }
8
 
9
 
9
-  /**
10
-   * @returns correct layout tree of nodes which are { type, data, children }
11
-   */
12
-  parse(api) {
10
+  parse(api: any): LayoutNode {
13
     if (api.topTabs) {
11
     if (api.topTabs) {
14
       return this._topTabs(api.topTabs);
12
       return this._topTabs(api.topTabs);
15
     } else if (api.sideMenu) {
13
     } else if (api.sideMenu) {
24
     throw new Error(`unknown LayoutType "${_.keys(api)}"`);
22
     throw new Error(`unknown LayoutType "${_.keys(api)}"`);
25
   }
23
   }
26
 
24
 
27
-  _topTabs(api) {
25
+  _topTabs(api): LayoutNode {
28
     return {
26
     return {
29
       type: LayoutType.TopTabs,
27
       type: LayoutType.TopTabs,
30
       data: { options: api.options },
28
       data: { options: api.options },
32
     };
30
     };
33
   }
31
   }
34
 
32
 
35
-  _sideMenu(api) {
33
+  _sideMenu(api): LayoutNode {
36
     return {
34
     return {
37
       type: LayoutType.SideMenuRoot,
35
       type: LayoutType.SideMenuRoot,
38
       data: { options: api.options },
36
       data: { options: api.options },
40
     };
38
     };
41
   }
39
   }
42
 
40
 
43
-  _sideMenuChildren(api) {
41
+  _sideMenuChildren(api): Array<LayoutNode> {
44
     if (!api.center) {
42
     if (!api.center) {
45
       throw new Error(`sideMenu.center is required`);
43
       throw new Error(`sideMenu.center is required`);
46
     }
44
     }
67
     return children;
65
     return children;
68
   }
66
   }
69
 
67
 
70
-  _bottomTabs(api) {
68
+  _bottomTabs(api): LayoutNode {
71
     return {
69
     return {
72
       type: LayoutType.BottomTabs,
70
       type: LayoutType.BottomTabs,
73
       data: { options: api.options },
71
       data: { options: api.options },
75
     };
73
     };
76
   }
74
   }
77
 
75
 
78
-  _stack(api) {
76
+  _stack(api): LayoutNode {
79
     return {
77
     return {
80
       type: LayoutType.Stack,
78
       type: LayoutType.Stack,
81
       data: { name: api.name, options: api.options },
79
       data: { name: api.name, options: api.options },
83
     };
81
     };
84
   }
82
   }
85
 
83
 
86
-  _component(api) {
84
+  _component(api): LayoutNode {
87
     return {
85
     return {
88
       type: LayoutType.Component,
86
       type: LayoutType.Component,
89
       data: { name: api.name, options: api.options, passProps: api.passProps },
87
       data: { name: api.name, options: api.options, passProps: api.passProps },

+ 1
- 1
lib/src/commands/values/LayoutNode.ts Vedi File

1
 import { LayoutType } from "./LayoutType";
1
 import { LayoutType } from "./LayoutType";
2
 
2
 
3
 export interface LayoutNode {
3
 export interface LayoutNode {
4
-  id: string;
4
+  id?: string;
5
   type: LayoutType;
5
   type: LayoutType;
6
   data: object;
6
   data: object;
7
   children: Array<LayoutNode>;
7
   children: Array<LayoutNode>;

lib/src/components/ComponentRegistry.test.js → lib/src/components/ComponentRegistry.test.ts Vedi File


lib/src/components/ComponentRegistry.js → lib/src/components/ComponentRegistry.ts Vedi File


lib/src/components/ComponentWrapper.test.js → lib/src/components/ComponentWrapper.test.ts Vedi File


lib/src/components/ComponentWrapper.js → lib/src/components/ComponentWrapper.ts Vedi File

1
-const _ = require('lodash');
1
+import * as  _ from 'lodash';
2
+import * as React from 'react';
2
 
3
 
3
-const React = require('react');
4
-const { Component } = require('react');
5
-
6
-class ComponentWrapper {
7
-  static wrap(componentName, OriginalComponent, store) {
8
-    return class extends Component {
4
+export class ComponentWrapper {
5
+  static wrap(componentName: string, OriginalComponent: any, store: any) {
6
+    return class extends React.Component<any, any> {
9
       constructor(props) {
7
       constructor(props) {
10
         super(props);
8
         super(props);
11
         this._saveComponentRef = this._saveComponentRef.bind(this);
9
         this._saveComponentRef = this._saveComponentRef.bind(this);
61
       render() {
59
       render() {
62
         return (
60
         return (
63
           <OriginalComponent
61
           <OriginalComponent
64
-            ref={this._saveComponentRef}
65
-            {...this.state.allProps}
66
-            componentId={this.state.componentId}
67
-            key={this.state.componentId}
62
+            ref= { this._saveComponentRef }
63
+        {...this.state.allProps }
64
+        componentId = { this.state.componentId }
65
+        key = { this.state.componentId }
68
           />
66
           />
69
         );
67
         );
70
       }
68
       }
71
     };
69
     };
72
   }
70
   }
73
 }
71
 }
74
-
75
-module.exports = ComponentWrapper;

lib/src/components/Lifecycle.test.js → lib/src/components/Lifecycle.test.ts Vedi File

1
-const Lifecycle = require('./Lifecycle');
2
-const Store = require('../components/Store');
1
+import { Lifecycle } from './Lifecycle';
2
+import { Store } from '../components/Store';
3
 
3
 
4
 describe('Lifecycle', () => {
4
 describe('Lifecycle', () => {
5
   let store;
5
   let store;

lib/src/components/Lifecycle.js → lib/src/components/Lifecycle.ts Vedi File

1
-class Lifecycle {
1
+export class Lifecycle {
2
+  private store: any;
3
+
2
   constructor(store) {
4
   constructor(store) {
3
     this.store = store;
5
     this.store = store;
4
     this.componentDidAppear = this.componentDidAppear.bind(this);
6
     this.componentDidAppear = this.componentDidAppear.bind(this);
27
     }
29
     }
28
   }
30
   }
29
 }
31
 }
30
-
31
-module.exports = Lifecycle;

lib/src/components/Store.test.js → lib/src/components/Store.test.ts Vedi File

1
-const Store = require('./Store');
1
+import { Store } from './Store';
2
 
2
 
3
 describe('Store', () => {
3
 describe('Store', () => {
4
   let uut;
4
   let uut;

lib/src/components/Store.js → lib/src/components/Store.ts Vedi File

1
-const _ = require('lodash');
1
+import * as _ from 'lodash';
2
+
3
+export class Store {
4
+  private propsByComponentId: {};
5
+  private componentsByName: {};
6
+  private refsById: {};
2
 
7
 
3
-class Store {
4
   constructor() {
8
   constructor() {
5
     this.propsByComponentId = {};
9
     this.propsByComponentId = {};
6
     this.componentsByName = {};
10
     this.componentsByName = {};
36
     _.unset(this.propsByComponentId, id);
40
     _.unset(this.propsByComponentId, id);
37
   }
41
   }
38
 }
42
 }
39
-
40
-module.exports = Store;

+ 1
- 1
lib/src/events/PrivateEventsListener.test.ts Vedi File

1
 import { PrivateEventsListener } from './PrivateEventsListener';
1
 import { PrivateEventsListener } from './PrivateEventsListener';
2
 import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver.mock';
2
 import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver.mock';
3
-import * as  Store from '../components/Store';
3
+import { Store } from '../components/Store';
4
 
4
 
5
 describe('PrivateEventsListener', () => {
5
 describe('PrivateEventsListener', () => {
6
   let uut: PrivateEventsListener;
6
   let uut: PrivateEventsListener;

lib/src/events/PublicEventsRegistry.test.js → lib/src/events/PublicEventsRegistry.test.ts Vedi File

1
-const PublicEventsRegistry = require('./PublicEventsRegistry');
2
-const NativeEventsReceiver = require('../adapters/NativeEventsReceiver.mock');
1
+import { PublicEventsRegistry } from './PublicEventsRegistry';
2
+import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver.mock';
3
 
3
 
4
 describe('PublicEventsRegistry', () => {
4
 describe('PublicEventsRegistry', () => {
5
   let uut;
5
   let uut;

lib/src/events/PublicEventsRegistry.js → lib/src/events/PublicEventsRegistry.ts Vedi File

1
-class PublicEventsRegistry {
1
+export class PublicEventsRegistry {
2
+  private nativeEventsReceiver: any;
3
+
2
   constructor(nativeEventsReceiver) {
4
   constructor(nativeEventsReceiver) {
3
     this.nativeEventsReceiver = nativeEventsReceiver;
5
     this.nativeEventsReceiver = nativeEventsReceiver;
4
   }
6
   }
7
     this.nativeEventsReceiver.registerAppLaunched(callback);
9
     this.nativeEventsReceiver.registerAppLaunched(callback);
8
   }
10
   }
9
 }
11
 }
10
-
11
-module.exports = PublicEventsRegistry;