Skip to content

Commit b63a14e

Browse files
committed
[worklets] Rename import to addModule for worklets. \o/
This fixes w3c#374. This didn't have as many text edits as I thought it would.
1 parent cdd6fed commit b63a14e

File tree

7 files changed

+28
-30
lines changed

7 files changed

+28
-30
lines changed

css-layout-api/EXPLAINER.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,19 @@ coordinates is:
4141
Getting Started
4242
---------------
4343

44-
First you'll need to import a script into the layout worklet.
44+
First you'll need to add a module script into the layout worklet.
4545

4646
```js
4747
if ('layoutWorklet' in CSS) {
48-
CSS.layoutWorklet.import('my-layout-script.js').then(() => {
49-
console.log('layout script installed!');
50-
});
48+
await CSS.layoutWorklet.addModule('my-layout-script.js');
49+
console.log('layout script installed!');
5150
}
5251
```
5352

5453
See the worklets [explainer](../worklets/EXPLAINER.md) for a more involved explanation of worklets.
5554

56-
After the promise returned from the `import` method resolves the layouts defined in the script will
57-
apply to the page.
55+
After the promise returned from the `addModule` method resolves the layouts defined in the script
56+
will apply to the page.
5857

5958
A Centering Layout
6059
------------------

css-paint-api/EXPLAINER.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ engine.
6464
Getting Started
6565
---------------
6666

67-
First you'll need to import a script into the paint worklet.
67+
First you'll need to add a module script into the paint worklet.
6868

6969
```js
7070
if ('paintWorklet' in CSS) {
71-
CSS.paintWorklet.import('my-paint-script.js').then(() => {
72-
console.log('paint script installed!');
73-
}
71+
await CSS.paintWorklet.addModule('my-paint-script.js');
72+
console.log('paint script installed!');
7473
}
7574
```
7675

css-paint-api/Overview.bs

+6-6
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ following steps:
521521
<div class=example-1></div>
522522
<div class=example-2></div>
523523
<script>
524-
CSS.paintWorklet.import('paint.js');
524+
CSS.paintWorklet.addModule('paint.js');
525525
</script>
526526
</pre>
527527

@@ -657,7 +657,7 @@ When the user agent wants to <dfn>invoke a paint callback</dfn> given |name|, |i
657657
&lt;div class=div-1>&lt;/div>
658658
&lt;div class=div-2>&lt;/div>
659659
&lt;script>
660-
CSS.paintWorklet.import('paint.js');
660+
CSS.paintWorklet.addModule('paint.js');
661661
&lt;/script>
662662
</pre>
663663
</div>
@@ -724,7 +724,7 @@ Animations API.
724724
initialValue: 'black',
725725
inherit: false
726726
});
727-
CSS.paintWorklet.import('circle.js');
727+
CSS.paintWorklet.addModule('circle.js');
728728
&lt;/script>
729729
</pre>
730730

@@ -772,7 +772,7 @@ loaded.
772772
name: '--image',
773773
syntax: '&lt;image&gt;'
774774
});
775-
CSS.paintWorklet.import('image-placeholder.js');
775+
CSS.paintWorklet.addModule('image-placeholder.js');
776776
&lt;/script>
777777
</pre>
778778

@@ -822,7 +822,7 @@ Example 3: Arcs {#example-3}
822822
&lt;div id="example">&lt;/div>
823823

824824
&lt;script>
825-
CSS.paintWorklet.import('arc.js');
825+
CSS.paintWorklet.addModule('arc.js');
826826
&lt;/script>
827827
</pre>
828828

@@ -905,7 +905,7 @@ h1 {
905905
&lt;/style>
906906

907907
&lt;script>
908-
CSS.paintWorklet.import('heading-color.js');
908+
CSS.paintWorklet.addModule('heading-color.js');
909909
&lt;/script>
910910
</pre>
911911

css-paint-api/arc/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
<div id="example"></div>
1515

1616
<script>
17-
(CSS.paintWorklet || paintWorklet).import('arc.js');
17+
(CSS.paintWorklet.addModule || paintWorkle.import)('arc.js');
1818
</script>

css-paint-api/chat/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
});
3434

3535
(async function() {
36-
await (CSS.paintWorklet || paintWorklet).import('chat.js');
36+
await (CSS.paintWorklet.addModule || paintWorkle.import)('chat.js');
3737

3838
const elem = document.getElementById('example');
3939
const add = document.getElementById('add');

css-paint-api/circle/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
initialValue: 'black',
2626
inherit: false
2727
});
28-
(CSS.paintWorklet || paintWorklet).import('circle.js');
28+
(CSS.paintWorklet.addModule || paintWorkle.import)('circle.js');
2929
</script>
3030

worklets/Overview.bs

+11-11
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ WorkletGlobalScope</a> algorithm.
162162

163163
The <a>event loop</a> is run on the <a>worklet global scope execution environment</a> defined above.
164164

165-
It is expected that only tasks associated {{Worklet/import()}}, the user agent invoking author
165+
It is expected that only tasks associated {{Worklet/addModule()}}, the user agent invoking author
166166
defined callbacks, and <a>microtasks</a> will use this <a>event loop</a>.
167167

168168
Note:
@@ -293,13 +293,13 @@ Issue: Merge this with https://html.spec.whatwg.org/multipage/workers.html#set-u
293293
Worklet {#worklet-section}
294294
--------------------------
295295

296-
The {{Worklet}} object provides the capability to import module scripts into its associated
296+
The {{Worklet}} object provides the capability to add module scripts into its associated
297297
{{WorkletGlobalScope}}s. The user agent can then create classes registered on the
298298
{{WorkletGlobalScope}}s and invoke their methods.
299299

300300
<pre class='idl'>
301301
interface Worklet {
302-
[NewObject] Promise&lt;void> import(USVString moduleURL, optional WorkletOptions options);
302+
[NewObject] Promise&lt;void> addModule(USVString moduleURL, optional WorkletOptions options);
303303
};
304304

305305
dictionary WorkletOptions {
@@ -325,7 +325,7 @@ additional {{WorkletGlobalScope}}s should be transparent to the author.
325325

326326
<div class='note'>
327327
Practically user agents aren't expected to implement the following algorithm using a
328-
thread-safe map. Instead when {{Worklet/import()}} is called user agents can fetch the module
328+
thread-safe map. Instead when {{Worklet/addModule()}} is called user agents can fetch the module
329329
graph on the main thread, and send the fetched sources (the data contained in the <a>module
330330
responses map</a>) to each thread which has a {{WorkletGlobalScope}}.
331331

@@ -338,7 +338,7 @@ A <dfn>pending tasks struct</dfn> is a <a>struct</a> consiting of:
338338
This is used by the algorithms below.
339339

340340
<div algorithm>
341-
When the <dfn method for=Worklet>import(|moduleURL|, |options|)</dfn> method is called on a
341+
When the <dfn method for=Worklet>addModule(|moduleURL|, |options|)</dfn> method is called on a
342342
{{Worklet}} object, the user agent <em>must</em> run the following steps:
343343
1. Let |promise| be <a>a new promise</a>.
344344

@@ -464,7 +464,7 @@ Note: Specifically, if a script fails to parse or fails to load over the network
464464
classes may have been registered correctly.
465465

466466
<div class=example>
467-
When an author imports code into a {{Worklet}} the code may run against multiple
467+
When an author adds code into a {{Worklet}} the code may run against multiple
468468
{{WorkletGlobalScope}}s, for example:
469469
<pre class='lang-javascript'>
470470
// script.js
@@ -473,7 +473,7 @@ Note: Specifically, if a script fails to parse or fails to load over the network
473473

474474
<pre class='lang-javascript'>
475475
// main.js
476-
await CSS.paintWorklet.import('script.js');
476+
await CSS.paintWorklet.addModule('script.js');
477477
</pre>
478478

479479
Behind the scenes the user agent may load the <code class='lang-javascript'>script.js</code>
@@ -546,8 +546,8 @@ Loading scripts into a worklet. {#example-single}
546546
-------------------------------------------------
547547

548548
<pre class='lang-javascript'>
549-
window.fakeWorklet1.import('script1.js');
550-
window.fakeWorklet1.import('script2.js');
549+
window.fakeWorklet1.addModule('script1.js');
550+
window.fakeWorklet1.addModule('script2.js');
551551

552552
// Assuming no other calls to fakeWorklet1 valid script loading orderings are:
553553
// 1. 'script1.js', 'script2.js'
@@ -559,8 +559,8 @@ Loading scripts into multiple worklets. {#example-multiple}
559559

560560
<pre class='lang-javascript'>
561561
Promise.all([
562-
window.fakeWorklet1.import('script1.js'),
563-
window.fakeWorklet2.import('script2.js')
562+
window.fakeWorklet1.addModule('script1.js'),
563+
window.fakeWorklet2.addModule('script2.js')
564564
]).then(function() {
565565
// Both scripts now have loaded code, can do a task which relies on this.
566566
});

0 commit comments

Comments
 (0)