File tree Expand file tree Collapse file tree 2 files changed +48
-19
lines changed
Expand file tree Collapse file tree 2 files changed +48
-19
lines changed Original file line number Diff line number Diff line change @@ -2,27 +2,46 @@ import u from '../../utils.js'
22
33const caches = [ ]
44
5- const cache = function ( rootElement , router , ctrlConfig , projectConfig ) {
6- projectConfig . scenes . forEach ( s => {
7- s . blocks . forEach ( b => {
8- const blk = caches . find ( d => d . type === b . type )
9- if ( blk && b . url ) {
10- const f = blk => {
11- fetch ( b . url ) . then ( data => {
12- data . text ( ) . then ( data => {
13- b . _cache = data
14- } )
15- } )
16- }
17- f ( blk )
18- }
19- } )
20- } )
21- }
5+ const cache = function ( rootElement , router , ctrlConfig , projectConfig ) { }
226
237const addCache = ob => {
248 caches . push ( ob )
259}
2610u . io . addCache = addCache
2711
12+ cache . run = config => {
13+ return new Promise ( ( resolve , reject ) => {
14+ let len = 0
15+ let cnt = 0
16+
17+ const blocks = config . scenes . reduce ( ( a , s ) => {
18+ s . blocks . reduce ( ( a2 , b ) => {
19+ const blk = caches . find ( d => d . type === b . type )
20+ if ( blk && b . url ) a . push ( b )
21+ } , [ ] )
22+ return a
23+ } , [ ] )
24+
25+ if ( blocks . length === 0 ) resolve ( )
26+
27+ blocks . forEach ( block => {
28+ const f = block => {
29+ fetch ( block . url ) . then ( data => {
30+ data . text ( ) . then ( data => {
31+ block . _cache = data
32+ cnt ++
33+ if ( cnt === len ) resolve ( )
34+ } )
35+ } ) . catch ( err => {
36+ cnt ++
37+ block . _cache = err + ': ' + block . url
38+ if ( cnt === len ) resolve ( )
39+ } )
40+ }
41+ len ++
42+ f ( block )
43+ } )
44+ } )
45+ }
46+
2847export { cache }
Original file line number Diff line number Diff line change @@ -17,9 +17,19 @@ const Presenta = function (el, config) {
1717
1818 const plugins = { ...controllers , ...modules , ...blocks }
1919 for ( const k in plugins ) if ( plugins [ k ] . init ) plugins [ k ] . init ( )
20- for ( const k in plugins ) if ( plugins [ k ] . run ) plugins [ k ] . run ( config )
2120
22- return new Container ( utils . select ( el ) , config )
21+ const all = [ ]
22+ for ( const k in plugins ) {
23+ if ( plugins [ k ] . run ) {
24+ all . push ( plugins [ k ] . run ( config ) )
25+ }
26+ }
27+
28+ return new Promise ( ( resolve , reject ) => {
29+ Promise . all ( all ) . then ( values => {
30+ resolve ( new Container ( utils . select ( el ) , config ) )
31+ } )
32+ } )
2333}
2434
2535addBlock ( 'group' , group ) // this to avoid circular dependencies warning, since removed implicit inclusion in block types
You can’t perform that action at this time.
0 commit comments