diff --git a/DEVLOG.md b/DEVLOG.md index 89a6afb0fc..5f532461b5 100755 --- a/DEVLOG.md +++ b/DEVLOG.md @@ -100,6 +100,9 @@ * **Translation Updates:** * German +### 2024-06-10 +* updated extensions.md with autoloading mechanism + ### 2024-06-07 * blocks: correctly record block snaps in "when () is edited" data, thanks, @dardoro, for the bug report! * objects: include customized primitives when enumerating primitive instances diff --git a/docs/Extensions.md b/docs/Extensions.md index a5ec2728ba..a6e1abad26 100644 --- a/docs/Extensions.md +++ b/docs/Extensions.md @@ -1,6 +1,6 @@ # Snap! Extensions -> Last updated May 23, 2024 +> Last updated June 10, 2024 Snap! Extensions take the idea of a library, and expand it by allowing you to add your own JavaScript code. Much of the work happens through two (hidden) primitive blocks. @@ -121,6 +121,10 @@ This lets you lazily initialize your extension by simply adding a "src_load(url)" command for your external JS file before calling any of its added functions. +#### autoloading JavaScript files + +If you want a library of custom blocks to automatically also load an external JavaScript file - and possibly also perform an initialization - you can include a global variable in the blocks library whose name has to begin with the word "module" enclosed in double-underscores (``__module__``), and whose value can be the url of a JavaScript file to be loaded. Notice that you can hide such a variable in the palette so the user will not be confused by its presence. + ### 5. Miscellaneous #### calling extension primitives in other JavaScript functions