File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ import LazyScratchBlocks from './tw-lazy-scratch-blocks' ;
2
+
3
+ /**
4
+ * Implements Scratch.gui API for unsandboxed extensions.
5
+ * @param {any } Scratch window.Scratch, mutated in place.
6
+ */
7
+ const implementGuiAPI = Scratch => {
8
+ Scratch . gui = {
9
+ /**
10
+ * Lazily get the internal ScratchBlocks object when it becomes available. It may never be
11
+ * available if, for example, the user never enters the editor.
12
+ *
13
+ * ScratchBlocks becoming available does not necessarily mean the user is in the editor due
14
+ * to getBlocklyEagerly() also existing.
15
+ *
16
+ * @returns {Promise<any> } Promise that may eventually resolve to ScratchBlocks
17
+ */
18
+ getBlockly : ( ) => new Promise ( resolve => LazyScratchBlocks . onLoaded ( resolve ) ) ,
19
+
20
+ /**
21
+ * Get the internal ScratchBlocks object as soon as possible. This lets you access it even
22
+ * if the user never enters the editor.
23
+ *
24
+ * This method is VERY SLOW and will cause A LOT OF CPU AND NETWORK ACTIVITY because it
25
+ * downloads and evaluates all of scratch-blocks, a multi-megabyte JavaScript bundle.
26
+ *
27
+ * @returns {Promise<any> } Promise that will resolve to ScratchBlocks.
28
+ */
29
+ getBlocklyEagerly : ( ) => LazyScratchBlocks . load ( )
30
+ } ;
31
+ } ;
32
+
33
+ export default implementGuiAPI ;
You can’t perform that action at this time.
0 commit comments