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