|
1 |
| -async function mapViews(widget, factoryFn, callback) { |
2 |
| - const { View, slot = {} } = await factoryFn(widget); |
3 |
| - const { containerSelector } = widget; |
| 1 | +function mapViews(widget, factoryFn, callback) { |
| 2 | + if (widget.$external.resolvedViews) { |
| 3 | + return mapResolvedViews(widget, callback); |
| 4 | + } |
4 | 5 |
|
5 |
| - // Add container selectors defined on widget instance after creation |
6 |
| - Object.keys(widget.slot).forEach((slotName) => { |
7 |
| - slot[slotName].isSlot = true; |
8 |
| - slot[slotName].containerSelector = widget.slot[slotName].containerSelector; |
9 |
| - }); |
10 |
| - |
11 |
| - return [ |
12 |
| - { View, containerSelector, isSlot: false }, |
13 |
| - ...Object.values(slot), |
14 |
| - ].map(({ View, containerSelector, isSlot }) => { |
15 |
| - callback({ |
16 |
| - View, |
17 |
| - isSlot, |
18 |
| - containerSelector, |
19 |
| - container: |
20 |
| - containerSelector && document?.querySelector(containerSelector), |
| 6 | + return factoryFn(widget).then(({ View, slot = {} }) => { |
| 7 | + const { containerSelector } = widget; |
| 8 | + // Add container selectors defined on widget instance after creation |
| 9 | + Object.keys(widget.slot).forEach((slotName) => { |
| 10 | + slot[slotName].isSlot = true; |
| 11 | + slot[slotName].containerSelector = |
| 12 | + widget.slot[slotName].containerSelector; |
21 | 13 | });
|
| 14 | + |
| 15 | + widget.$external.resolvedViews = [ |
| 16 | + { View, containerSelector, isSlot: false }, |
| 17 | + ...Object.values(slot), |
| 18 | + ]; |
| 19 | + |
| 20 | + return mapResolvedViews(widget, callback); |
22 | 21 | });
|
23 | 22 | }
|
24 | 23 |
|
| 24 | +function mapResolvedViews(widget, callback) { |
| 25 | + return widget.$external.resolvedViews.map( |
| 26 | + ({ View, containerSelector, isSlot }) => { |
| 27 | + callback({ |
| 28 | + View, |
| 29 | + isSlot, |
| 30 | + containerSelector, |
| 31 | + container: |
| 32 | + containerSelector && document?.querySelector(containerSelector), |
| 33 | + }); |
| 34 | + } |
| 35 | + ); |
| 36 | +} |
| 37 | + |
25 | 38 | export { mapViews };
|
0 commit comments