File tree Expand file tree Collapse file tree 1 file changed +5
-21
lines changed Expand file tree Collapse file tree 1 file changed +5
-21
lines changed Original file line number Diff line number Diff line change 1
1
import observer from '@cocreate/observer' ;
2
2
3
- export function addComponent ( key , component ) {
4
- this [ key ] = component ;
5
- }
6
-
7
- export function removeComponent ( key ) {
8
- if ( this [ key ] ) { }
9
- }
10
-
11
3
function listen ( callback , selector ) {
12
4
13
5
function observerCallback ( { target } ) {
@@ -54,24 +46,16 @@ function listen(callback, selector) {
54
46
55
47
}
56
48
57
- export async function lazyLoad ( name , selector , cb ) {
58
- async function cc ( ) {
59
- let component = ( await cb ( ) ) . default ;
60
- Object . assign ( window . CoCreate , {
61
- [ name ] : component
62
- } )
63
- }
64
-
49
+ export async function lazyLoad ( name , selector , callback ) {
65
50
if ( document . querySelector ( selector ) )
66
- await cc ( )
51
+ await dependency ( name , await callback ( ) )
67
52
else
68
- listen ( cc , selector )
69
-
53
+ listen ( callback , selector )
70
54
}
71
55
72
56
export async function dependency ( name , promise ) {
73
- let module = await promise ;
57
+ let component = await promise ;
74
58
Object . assign ( window . CoCreate , {
75
- [ name ] : module . default
59
+ [ name ] : component . default
76
60
} ) ;
77
61
}
You can’t perform that action at this time.
0 commit comments