Skip to content

Commit 5b0eccc

Browse files
committed
[worklets] Add example to {{Worklet/import}} section.
Addresses confusion in w3c#373.
1 parent a626bf7 commit 5b0eccc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

worklets/Overview.bs

+27
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,33 @@ the user agent <em>must</em> run the following steps:
365365

366366
7. Return |promise|.
367367

368+
<div class=example>
369+
When an author imports code into a {{Worklet}} the code may run against multiple
370+
{{WorkletGlobalScope}}s, for example:
371+
<pre class='lang-javascript'>
372+
// script.js
373+
console.log('Hello from a WorkletGlobalScope!');
374+
</pre>
375+
376+
<pre class='lang-javascript'>
377+
// main.js
378+
await CSS.paintWorklet.import('script.js');
379+
</pre>
380+
381+
Behind the scenes the user-agent may load the <code class='lang-javascript'>script.js</code>
382+
into 4 global scopes, in which case the debugging tools for the user-agent would print:
383+
<pre class='lang-javascript'>
384+
[paintWorklet#1] Hello from a WorkletGlobalScope!
385+
[paintWorklet#4] Hello from a WorkletGlobalScope!
386+
[paintWorklet#2] Hello from a WorkletGlobalScope!
387+
[paintWorklet#3] Hello from a WorkletGlobalScope!
388+
</pre>
389+
390+
If the user-agent decided to kill and restart a {{WorkletGlobalScope}} number 3 in this example,
391+
it would print <code class='lang-javascript'>[paintWorklet#3] Hello from a
392+
WorkletGlobalScope!</code> again in the debugging tools when this occurs.
393+
</div>
394+
368395
Issue(w3c/css-houdini-drafts#47): Need ability to load code into a {{WorkletGlobalScope}}
369396
declaratively.
370397

0 commit comments

Comments
 (0)