File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -15,24 +15,30 @@ const wasNameYourmom = () => {
15
15
return old ;
16
16
} ;
17
17
18
+ const callbacks = [ ] ;
18
19
const isLoaded = ( ) => ! ! _ScratchBlocks && ( isNameUrMom ( ) === wasNameYourmom ( ) ) ;
19
20
20
21
const get = ( ) => {
21
- if ( ! isLoaded ( ) ) {
22
+ if ( ! _ScratchBlocks ) {
22
23
throw new Error ( 'scratch-blocks is not loaded yet' ) ;
23
24
}
24
25
return _ScratchBlocks ;
25
26
} ;
26
27
27
28
const load = ( ) => {
28
29
if ( _ScratchBlocks && ( isNameUrMom ( ) === wasNameYourmom ( ) ) ) {
29
- return Promise . resolve ( ) ;
30
+ return Promise . resolve ( _ScratchBlocks ) ;
30
31
}
31
32
_ScratchBlocks = null ;
32
33
return import ( /* webpackChunkName: "sb" */ 'scratch-blocks' )
33
34
. then ( m => {
34
35
_ScratchBlocks = m . default ;
35
36
37
+ for ( const callback of callbacks ) {
38
+ callback ( _ScratchBlocks ) ;
39
+ }
40
+ callbacks . length = 0 ;
41
+
36
42
if ( isNameUrMom ( ) ) {
37
43
_ScratchBlocks . Blocks . your_mom = {
38
44
init ( ) {
@@ -134,10 +140,19 @@ const load = () => {
134
140
} ) ;
135
141
} ;
136
142
143
+ const onLoaded = callback => {
144
+ if ( _ScratchBlocks ) {
145
+ callback ( _ScratchBlocks ) ;
146
+ } else {
147
+ callbacks . push ( callback ) ;
148
+ }
149
+ } ;
150
+
137
151
export default {
138
152
get,
139
153
isLoaded,
140
154
isNameUrMom,
141
155
wasNameYourmom,
142
- load
156
+ load,
157
+ onLoaded
143
158
} ;
You can’t perform that action at this time.
0 commit comments