소스 검색

trying to convert to a tree

Daniel Zlotin 7 년 전
부모
커밋
11cbaddf37
6개의 변경된 파일127개의 추가작업 그리고 208개의 파일을 삭제
  1. 8
    1
      ios/RNNControllerFactory.m
  2. 7
    2
      src/commands/Commands.test.js
  3. 1
    1
      src/commands/LayoutTreeParser.js
  4. 20
    113
      src/commands/LayoutTreeParser.test.js
  5. 91
    0
      src/commands/SimpleLayouts.js
  6. 0
    91
      src/commands/ValidCommands.js

+ 8
- 1
ios/RNNControllerFactory.m 파일 보기

@@ -11,7 +11,14 @@
11 11
     NSString* containerName = layout[@"container"][@"name"];
12 12
     NSString* containerId = layout[@"container"][@"id"];
13 13
     
14
-    RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:RNN.instance.bridge moduleName:containerName initialProperties:@{@"containerId": containerId}];
14
+    return [RNNControllerFactory create:containerName containerId:containerId];
15
+}
16
+
17
++(UIViewController*)create:(NSString*)containerName containerId:(NSString*)containerId
18
+{
19
+    RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:RNN.instance.bridge
20
+                                                      moduleName:containerName
21
+                                               initialProperties:@{@"containerId": containerId}];
15 22
     
16 23
     UIViewController* controller = [UIViewController new];
17 24
     controller.view = reactView;

+ 7
- 2
src/commands/Commands.test.js 파일 보기

@@ -4,7 +4,7 @@ describe('Commands', () => {
4 4
     startApp: jest.fn()
5 5
   };
6 6
   const mockIdProvider = {
7
-    generate: (prefix) => `${prefix}UNIQUE`
7
+    generate: (prefix) => `${prefix}UNIQUE_ID`
8 8
   };
9 9
 
10 10
   beforeEach(() => {
@@ -20,7 +20,12 @@ describe('Commands', () => {
20 20
         }
21 21
       });
22 22
       expect(mockCommandsSender.startApp).toHaveBeenCalledTimes(1);
23
-      //TODO
23
+      expect(mockCommandsSender.startApp).toHaveBeenCalledWith({
24
+        container: {
25
+          name: 'com.example.MyScreen',
26
+          id: 'containerUNIQUE_ID'
27
+        }
28
+      });
24 29
     });
25 30
   });
26 31
 });

+ 1
- 1
src/commands/LayoutTreeParser.js 파일 보기

@@ -6,7 +6,7 @@ export default class LayoutTreeParser {
6 6
   }
7 7
 
8 8
   parse(params) {
9
-    const layout = _.merge({}, params);
9
+    const layout = _.cloneDeep(params);
10 10
     if (layout.container) {
11 11
       layout.container.id = this.uniqueIdProvider.generate(`container`);
12 12
     }

+ 20
- 113
src/commands/LayoutTreeParser.test.js 파일 보기

@@ -1,121 +1,28 @@
1
-xdescribe('LayoutTreeParser', () => {
2
-  let LayoutBuilder;
1
+import * as SimpleLayouts from './SimpleLayouts';
2
+
3
+describe('LayoutTreeParser', () => {
4
+  let uut;
3 5
 
4 6
   beforeEach(() => {
5
-    jest.mock('../adapters/UniqueIdProvider');
6
-    LayoutBuilder = require('./LayoutTreeParser');
7
+    const uniqueIdProvider = {generate: (p) => `${p}UNIQUE_ID`};
8
+    const LayoutTreeParser = require('./LayoutTreeParser').default;
9
+    uut = new LayoutTreeParser(uniqueIdProvider);
7 10
   });
8 11
 
9
-  describe('parse', () => {
10
-    it('deeply clones input params', () => {
11
-      const input = {inner: {value: 1}};
12
-      expect(LayoutBuilder.parse(input)).not.toBe(input);
13
-      expect(LayoutBuilder.parse(input).inner).not.toBe(input.inner);
14
-    });
15
-
16
-    it('adds uniqueId to passed container', () => {
17
-      expect(LayoutBuilder.parse({
18
-        container: {
19
-          name: 'com.example.MyScreen'
20
-        }
21
-      })).toEqual({
22
-        container: {
23
-          name: 'com.example.MyScreen',
24
-          id: 'containerUNIQUE'
25
-        }
26
-      });
27
-    });
12
+  it('returns a deep clone', () => {
13
+    const input = {inner: {foo: {bar: 1}}};
14
+    expect(uut.parse(input)).not.toBe(input);
15
+    expect(uut.parse(input).inner).not.toBe(input.inner);
16
+    expect(uut.parse(input).inner.foo).not.toBe(input.inner.foo);
17
+  });
28 18
 
29
-    it('adds uniqueId to passed sideMenu', () => {
30
-      expect(LayoutBuilder.parse({
31
-        container: {
32
-          name: 'com.example.MyScreen'
33
-        },
34
-        sideMenu: {
35
-          left: {
36
-            name: 'com.example.SideMenu1'
37
-          },
38
-          right: {
39
-            name: 'com.example.SideMenu2'
40
-          }
41
-        }
42
-      })).toEqual({
43
-        container: {
44
-          name: 'com.example.MyScreen',
45
-          id: 'containerUNIQUE'
46
-        },
47
-        sideMenu: {
48
-          left: {
49
-            name: 'com.example.SideMenu1',
50
-            id: 'containerUNIQUE'
51
-          },
52
-          right: {
53
-            name: 'com.example.SideMenu2',
54
-            id: 'containerUNIQUE'
55
-          }
56
-        }
57
-      });
58
-    });
19
+  it('adds uniqueId to containers', () => {
20
+    const input = {container: {}};
21
+    expect(uut.parse(input)).toEqual({container: {id: 'containerUNIQUE_ID'}});
22
+  });
59 23
 
60
-    it('adds uniqueId to passed tabs', () => {
61
-      expect(LayoutBuilder.parse({
62
-        tabs: [
63
-          {
64
-            container: {
65
-              name: 'com.example.FirstTab'
66
-            }
67
-          },
68
-          {
69
-            container: {
70
-              name: 'com.example.SecondTab'
71
-            }
72
-          },
73
-          {
74
-            container: {
75
-              name: 'com.example.FirstTab'
76
-            }
77
-          }
78
-        ],
79
-        sideMenu: {
80
-          left: {
81
-            name: 'com.example.Menu1'
82
-          },
83
-          right: {
84
-            name: 'com.example.Menu2'
85
-          }
86
-        }
87
-      })).toEqual({
88
-        tabs: [
89
-          {
90
-            container: {
91
-              name: 'com.example.FirstTab',
92
-              id: 'containerUNIQUE'
93
-            }
94
-          },
95
-          {
96
-            container: {
97
-              name: 'com.example.SecondTab',
98
-              id: 'containerUNIQUE'
99
-            }
100
-          },
101
-          {
102
-            container: {
103
-              name: 'com.example.FirstTab',
104
-              id: 'containerUNIQUE'
105
-            }
106
-          }
107
-        ],
108
-        sideMenu: {
109
-          left: {
110
-            name: 'com.example.Menu1',
111
-            id: 'containerUNIQUE'
112
-          },
113
-          right: {
114
-            name: 'com.example.Menu2',
115
-            id: 'containerUNIQUE'
116
-          }
117
-        }
118
-      });
119
-    });
24
+  it('parses simple structures', () => {
25
+    uut.parse(SimpleLayouts.singleScreenApp);
26
+    //TODO
120 27
   });
121 28
 });

+ 91
- 0
src/commands/SimpleLayouts.js 파일 보기

@@ -0,0 +1,91 @@
1
+export const singleScreenApp = {
2
+  container: {
3
+    name: 'com.example.MyScreen'
4
+  }
5
+};
6
+
7
+export const tabBasedApp = {
8
+  tabs: [
9
+    {
10
+      container: {
11
+        name: 'com.example.FirstTab'
12
+      }
13
+    },
14
+    {
15
+      container: {
16
+        name: 'com.example.SecondTab'
17
+      }
18
+    },
19
+    {
20
+      container: {
21
+        name: 'com.example.FirstTab'
22
+      }
23
+    }
24
+  ]
25
+};
26
+
27
+export const singleWithSideMenu = {
28
+  container: {
29
+    name: 'com.example.MyScreen'
30
+  },
31
+  sideMenu: {
32
+    left: {
33
+      container: {
34
+        name: 'com.example.MyScreen'
35
+      }
36
+    }
37
+  }
38
+};
39
+
40
+export const singleWithRightSideMenu = {
41
+  container: {
42
+    name: 'com.example.MyScreen'
43
+  },
44
+  sideMenu: {
45
+    right: {
46
+      name: 'com.example.Menu'
47
+    }
48
+  }
49
+};
50
+
51
+export const singleWithBothMenus = {
52
+  container: {
53
+    name: 'com.example.MyScreen'
54
+  },
55
+  sideMenu: {
56
+    left: {
57
+      name: 'com.example.Menu1'
58
+    },
59
+    right: {
60
+      name: 'com.example.Menu2'
61
+    }
62
+  }
63
+};
64
+
65
+export const tabBasedWithSideMenu = {
66
+  tabs: [
67
+    {
68
+      container: {
69
+        name: 'com.example.FirstTab'
70
+      }
71
+    },
72
+    {
73
+      container: {
74
+        name: 'com.example.SecondTab'
75
+      }
76
+    },
77
+    {
78
+      container: {
79
+        name: 'com.example.FirstTab'
80
+      }
81
+    }
82
+  ],
83
+  sideMenu: {
84
+    left: {
85
+      name: 'com.example.Menu1'
86
+    },
87
+    right: {
88
+      name: 'com.example.Menu2'
89
+    }
90
+  }
91
+};

+ 0
- 91
src/commands/ValidCommands.js 파일 보기

@@ -1,91 +0,0 @@
1
-//export const singleScreenApp = {
2
-//  container: {
3
-//    name: 'com.example.MyScreen'
4
-//  }
5
-//};
6
-//
7
-//export const tabBasedApp = {
8
-//  tabs: [
9
-//    {
10
-//      container: {
11
-//        name: 'com.example.FirstTab'
12
-//      }
13
-//    },
14
-//    {
15
-//      container: {
16
-//        name: 'com.example.SecondTab'
17
-//      }
18
-//    },
19
-//    {
20
-//      container: {
21
-//        name: 'com.example.FirstTab'
22
-//      }
23
-//    }
24
-//  ]
25
-//};
26
-//
27
-//export const singleWithSideMenu = {
28
-//  container: {
29
-//    name: 'com.example.MyScreen'
30
-//  },
31
-//  sideMenu: {
32
-//    left: {
33
-//      container: {
34
-//        name: 'com.example.MyScreen'
35
-//      }
36
-//    }
37
-//  }
38
-//};
39
-//
40
-//export const singleWithRightSideMenu = {
41
-//  container: {
42
-//    name: 'com.example.MyScreen'
43
-//  },
44
-//  sideMenu: {
45
-//    right: {
46
-//      name: 'com.example.Menu'
47
-//    }
48
-//  }
49
-//};
50
-//
51
-//export const singleWithBothMenus = {
52
-//  container: {
53
-//    name: 'com.example.MyScreen'
54
-//  },
55
-//  sideMenu: {
56
-//    left: {
57
-//      name: 'com.example.Menu1'
58
-//    },
59
-//    right: {
60
-//      name: 'com.example.Menu2'
61
-//    }
62
-//  }
63
-//};
64
-//
65
-//export const tabBasedWithSideMenu = {
66
-//  tabs: [
67
-//    {
68
-//      container: {
69
-//        name: 'com.example.FirstTab'
70
-//      }
71
-//    },
72
-//    {
73
-//      container: {
74
-//        name: 'com.example.SecondTab'
75
-//      }
76
-//    },
77
-//    {
78
-//      container: {
79
-//        name: 'com.example.FirstTab'
80
-//      }
81
-//    }
82
-//  ],
83
-//  sideMenu: {
84
-//    left: {
85
-//      name: 'com.example.Menu1'
86
-//    },
87
-//    right: {
88
-//      name: 'com.example.Menu2'
89
-//    }
90
-//  }
91
-//};