Browse Source

Crawl layout only after dispatching events so it will contain passProps (#5126)

Yogev Ben David 5 years ago
parent
commit
d3d01c221f
1 changed files with 27 additions and 18 deletions
  1. 27
    18
      lib/src/commands/Commands.ts

+ 27
- 18
lib/src/commands/Commands.ts View File

21
   public setRoot(simpleApi: LayoutRoot) {
21
   public setRoot(simpleApi: LayoutRoot) {
22
     const input = _.cloneDeep(simpleApi);
22
     const input = _.cloneDeep(simpleApi);
23
     const root = this.layoutTreeParser.parse(input.root);
23
     const root = this.layoutTreeParser.parse(input.root);
24
-    this.layoutTreeCrawler.crawl(root);
25
 
24
 
26
     const modals = _.map(input.modals, (modal) => {
25
     const modals = _.map(input.modals, (modal) => {
27
-      const modalLayout = this.layoutTreeParser.parse(modal);
28
-      this.layoutTreeCrawler.crawl(modalLayout);
29
-      return modalLayout;
26
+      return this.layoutTreeParser.parse(modal);
30
     });
27
     });
31
 
28
 
32
     const overlays = _.map(input.overlays, (overlay) => {
29
     const overlays = _.map(input.overlays, (overlay) => {
33
-      const overlayLayout = this.layoutTreeParser.parse(overlay);
34
-      this.layoutTreeCrawler.crawl(overlayLayout);
35
-      return overlayLayout;
30
+      return this.layoutTreeParser.parse(overlay);
36
     });
31
     });
37
 
32
 
38
     const commandId = this.uniqueIdProvider.generate('setRoot');
33
     const commandId = this.uniqueIdProvider.generate('setRoot');
39
-    const result = this.nativeCommandsSender.setRoot(commandId, { root, modals, overlays });
40
     this.commandsObserver.notify('setRoot', { commandId, layout: { root, modals, overlays } });
34
     this.commandsObserver.notify('setRoot', { commandId, layout: { root, modals, overlays } });
35
+
36
+    this.layoutTreeCrawler.crawl(root);
37
+    modals.forEach(modalLayout => {
38
+      this.layoutTreeCrawler.crawl(modalLayout);
39
+    });
40
+    overlays.forEach(overlayLayout => {
41
+      this.layoutTreeCrawler.crawl(overlayLayout);
42
+    })
43
+
44
+    const result = this.nativeCommandsSender.setRoot(commandId, { root, modals, overlays });
41
     return result;
45
     return result;
42
   }
46
   }
43
 
47
 
60
   public showModal(layout: Layout) {
64
   public showModal(layout: Layout) {
61
     const layoutCloned = _.cloneDeep(layout);
65
     const layoutCloned = _.cloneDeep(layout);
62
     const layoutNode = this.layoutTreeParser.parse(layoutCloned);
66
     const layoutNode = this.layoutTreeParser.parse(layoutCloned);
67
+    
68
+    const commandId = this.uniqueIdProvider.generate('showModal');
69
+    this.commandsObserver.notify('showModal', { commandId, layout: layoutNode });
63
     this.layoutTreeCrawler.crawl(layoutNode);
70
     this.layoutTreeCrawler.crawl(layoutNode);
64
 
71
 
65
-    const commandId = this.uniqueIdProvider.generate('showModal');
66
     const result = this.nativeCommandsSender.showModal(commandId, layoutNode);
72
     const result = this.nativeCommandsSender.showModal(commandId, layoutNode);
67
-    this.commandsObserver.notify('showModal', { commandId, layout: layoutNode });
68
     return result;
73
     return result;
69
   }
74
   }
70
 
75
 
84
 
89
 
85
   public push(componentId: string, simpleApi: Layout) {
90
   public push(componentId: string, simpleApi: Layout) {
86
     const input = _.cloneDeep(simpleApi);
91
     const input = _.cloneDeep(simpleApi);
87
-
88
     const layout = this.layoutTreeParser.parse(input);
92
     const layout = this.layoutTreeParser.parse(input);
89
-    this.layoutTreeCrawler.crawl(layout);
90
 
93
 
91
     const commandId = this.uniqueIdProvider.generate('push');
94
     const commandId = this.uniqueIdProvider.generate('push');
92
-    const result = this.nativeCommandsSender.push(commandId, componentId, layout);
93
     this.commandsObserver.notify('push', { commandId, componentId, layout });
95
     this.commandsObserver.notify('push', { commandId, componentId, layout });
96
+    this.layoutTreeCrawler.crawl(layout);
97
+
98
+    const result = this.nativeCommandsSender.push(commandId, componentId, layout);
94
     return result;
99
     return result;
95
   }
100
   }
96
 
101
 
118
   public setStackRoot(componentId: string, children: Layout[]) {
123
   public setStackRoot(componentId: string, children: Layout[]) {
119
     const input = _.map(_.cloneDeep(children), (simpleApi) => {
124
     const input = _.map(_.cloneDeep(children), (simpleApi) => {
120
       const layout = this.layoutTreeParser.parse(simpleApi);
125
       const layout = this.layoutTreeParser.parse(simpleApi);
121
-      this.layoutTreeCrawler.crawl(layout);
122
       return layout;
126
       return layout;
123
     });
127
     });
128
+  
124
     const commandId = this.uniqueIdProvider.generate('setStackRoot');
129
     const commandId = this.uniqueIdProvider.generate('setStackRoot');
125
-    const result = this.nativeCommandsSender.setStackRoot(commandId, componentId, input);
126
     this.commandsObserver.notify('setStackRoot', { commandId, componentId, layout: input });
130
     this.commandsObserver.notify('setStackRoot', { commandId, componentId, layout: input });
131
+    input.forEach(layoutNode => {
132
+      this.layoutTreeCrawler.crawl(layoutNode);
133
+    })
134
+
135
+    const result = this.nativeCommandsSender.setStackRoot(commandId, componentId, input);
127
     return result;
136
     return result;
128
   }
137
   }
129
 
138
 
130
   public showOverlay(simpleApi: Layout) {
139
   public showOverlay(simpleApi: Layout) {
131
     const input = _.cloneDeep(simpleApi);
140
     const input = _.cloneDeep(simpleApi);
132
-
133
     const layout = this.layoutTreeParser.parse(input);
141
     const layout = this.layoutTreeParser.parse(input);
142
+    
143
+    const commandId = this.uniqueIdProvider.generate('showOverlay');
144
+    this.commandsObserver.notify('showOverlay', { commandId, layout });
134
     this.layoutTreeCrawler.crawl(layout);
145
     this.layoutTreeCrawler.crawl(layout);
135
 
146
 
136
-    const commandId = this.uniqueIdProvider.generate('showOverlay');
137
     const result = this.nativeCommandsSender.showOverlay(commandId, layout);
147
     const result = this.nativeCommandsSender.showOverlay(commandId, layout);
138
-    this.commandsObserver.notify('showOverlay', { commandId, layout });
139
     return result;
148
     return result;
140
   }
149
   }
141
 
150