Skip to content

Commit 48d9fe4

Browse files
committed
Remove State{less,ful}Animator interfaces (w3c#850, w3c#907)
1 parent 01ddded commit 48d9fe4

File tree

1 file changed

+44
-50
lines changed

1 file changed

+44
-50
lines changed

css-animationworklet/Overview.bs

+44-50
Original file line numberDiff line numberDiff line change
@@ -155,32 +155,23 @@ and each one is associated with a {{WorkletAnimation}} instance. An animator can
155155
instantiated by construction of a {{WorkletAnimation}}.
156156

157157

158-
Two animators types are supported: {{StatelessAnimator}} and {{StatefulAnimator}} each
158+
Two animators types are supported: <a>Stateless Animator</a> and <a>Stateful Animator</a> each
159159
providing a different state management strategy.
160160

161161

162-
StatelessAnimator Interface {#stateless-animator-desc}
162+
Stateless Animator {#stateless-animator-desc}
163163
---------------------------
164164

165-
This interface represents a stateless animator. This type of animator does not depend on any local
166-
state either stored on the instance or global scope. Effectively, the animate function of an
167-
{{StatelessAnimator}} can be treated as a pure function with the expectation that given the same
168-
input, it produces the same output.
169-
170-
171-
172-
<xmp class='idl'>
173-
[Exposed=AnimationWorklet, Global=AnimationWorklet, Constructor (optional any options)]
174-
interface StatelessAnimator {
175-
};
176-
</xmp>
177-
165+
A <dfn>Stateless Animator</dfn> is a type of animator does not depend on any local state either
166+
stored on the instance or global scope. Effectively, the animate function of an <a>Stateless
167+
Animator</a> can be treated as a pure function with the expectation that given the same input, it
168+
produces the same output.
178169

179170

180171
<div class='note'>
181-
This is how the class should look.
172+
This is how an stateless animator class should look.
182173
<pre class='lang-javascript'>
183-
class FooAnimator extends StatelessAnimator {
174+
class FooAnimator {
184175
constructor(options) {
185176
// Called when a new animator is instantiated.
186177
}
@@ -193,14 +184,14 @@ interface StatelessAnimator {
193184

194185
Note: The statelessness allows an animation worklet to perform optimization such as producing
195186
multiple animation frames in parallel and performing very cheap teardown and setup. Using
196-
StatelessAnimator is highly recommended to enable such optimizations.
187+
<a>Stateless Animator</a> is highly recommended to enable such optimizations.
197188

198-
StatefulAnimator Interface {#stateful-animator-desc}
189+
Stateful Animator {#stateful-animator-desc}
199190
---------------------------
200191

201-
This interface represents a stateful animator. This animator can have local state and animation
202-
worklet guarantees that it maintains this state as long as the stateful animator fulfills the
203-
contract required by this interface as described following.
192+
A <dfn>Stateful Animator</dfn> is a type of animator that can have local state and animation worklet
193+
guarantees that it maintains this state as long as the stateful animator fulfills the contract
194+
required by its interface as described following.
204195

205196

206197
<a>Animation worklet</a> maintains a set of {{WorkletGlobalScope}}s which may exist across different
@@ -210,29 +201,20 @@ effect is mutable only in a certain thread). Animation worklet guarantees that a
210201
instance's state is maintained even if the instance is respawned in a different global scope.
211202

212203
The basic mechanism for maintaining the state is that the animation worklet snapshots the local
213-
state that is exposed via the {{StatefulAnimator/state}} function and then reifies it so that it can
214-
be passed into the constructor when the animator instance is respawned at a later time in a
215-
potentially different global scope. The <a>migrate an animator instance</a> algorithm specifies this
216-
process in details.
204+
state that is exposed via the <a>state function</a> and then reifies it so that it can be passed
205+
into the constructor when the animator instance is respawned at a later time in a potentially
206+
different global scope. The <a>migrate an animator instance</a> algorithm specifies this process in
207+
details.
217208

218209
A user-defined stateful animator is expected to fulfill the required contract which is that its
219210
state function returns an object representing its state that can be serialized using structured
220211
serialized algorithm and that it can also recreate its state given that same object passed to
221212
its constructor.
222213

223-
<xmp class='idl'>
224-
[Exposed=AnimationWorklet, Global=AnimationWorklet,
225-
Constructor (optional any options, optional any state)]
226-
interface StatefulAnimator {
227-
any state();
228-
};
229-
</xmp>
230-
231-
232214
<div class='note'>
233-
This is how the class should look.
215+
This is how a stateful animator class should look.
234216
<pre class='lang-javascript'>
235-
class BarAnimator extends StatefulAnimator {
217+
class BarAnimator {
236218
constructor(options, state) {
237219
// Called when a new animator is instantiated (either first time or after being respawned).
238220
this.currentVelocity = state ? state.velocity : 0;
@@ -264,8 +246,13 @@ animation as needed by {{AnimationWorkletGlobalScope}}. It consists of:
264246

265247
- An <dfn>animate function</dfn> which is a <a>Function</a> <a>callback function</a> type.
266248

267-
- A <dfn>stateful flag</dfn>
249+
- A <dfn>state function</dfn> which is a <a>Function</a> <a>callback function</a> type.
250+
251+
- A <dfn>stateful flag</dfn>.
252+
268253

254+
A <dfn>stateful animator definition</dfn> is an <a>animator definition</a> whose <a>stateful
255+
flag</a> is <b>true</b>.
269256

270257

271258
Registering an Animator Definition {#registering-animator-definition}
@@ -285,6 +272,9 @@ callback AnimatorInstanceConstructor = any (any options, optional any state);
285272

286273
</xmp>
287274

275+
Note that to register a <a>stateful animator definition</a> it is simply enough for the registered
276+
class to have a state function.
277+
288278
<div algorithm="register-animator">
289279

290280
When the <dfn method for=AnimationWorkletGlobalScope>registerAnimator(|name|, |animatorCtor|)</dfn>
@@ -304,24 +294,27 @@ following steps:
304294
4. Let |prototype| be the result of <a>Get</a>(|animatorCtor|, "prototype").
305295

306296

307-
5. If <a>SameValue</a>(|prototype|, {{StatelessAnimator}}) is <b>true</b> set |stateful| to be
308-
<b>false</b>, otherwise if <a>SameValue</a>(|prototype|, {{StatefulAnimator}}) is
309-
<b>true</b> set |stateful| to be <b>true</b>, otherwise <a>throw</a> a <a>TypeError</a> and
310-
abort all these steps.
311-
312-
6. Let |animateValue| be the result of <a>Get</a>(|prototype|, "animate").
297+
5. Let |animateFuncValue| be the result of <a>Get</a>(|prototype|, "animate").
313298

314-
7. Let |animate| be the result of <a>converting</a> |animateValue| to the <a>Function</a>
299+
6. Let |animateFunc| be the result of <a>converting</a> |animateFuncValue| to the <a>Function</a>
315300
<a>callback function</a> type. If an exception is thrown, rethrow the exception and abort
316301
all these steps.
317302

318-
8. Let |definition| be a new <a>animator definition</a> with:
303+
7. Let |stateFuncValue| be the result of <a>Get</a>(|prototype|, "state").
304+
305+
8. Let |stateFunc| be the result of <a>converting</a> |stateFuncValue| to the <a>Function</a>
306+
<a>callback function</a> type, If an exception is thrown, set |stateful| to be <b>false</b>,
307+
otherwise set |stateful| to be <b>true</b> and |stateFunc| to be undefined.
308+
309+
9. Let |definition| be a new <a>animator definition</a> with:
319310

320311
- <a>animator name</a> being |name|
321312

322313
- <a>class constructor</a> being |animatorCtor|
323314

324-
- <a>animate function</a> being |animate|
315+
- <a>animate function</a> being |animateFunc|
316+
317+
- <a>state function</a> being |stateFunc|
325318

326319
- <a>stateful flag</a> being |stateful|
327320

@@ -352,7 +345,8 @@ and owns the instance specific state such as animation effect and timeline. It c
352345
- An <dfn>animator serialized options</dfn> which is a serializable object.
353346

354347
A <dfn>stateful animator instance</dfn> is an <a>animator instance</a> whose corresponding
355-
<a>animator definition</a>'s <a>stateful flag</a> is <b>true</b>.
348+
definition is a <a>stateful animator definition</a>.
349+
356350

357351

358352
Creating an Animator Instance {#creating-animator-instance}
@@ -852,7 +846,7 @@ animation.play();
852846

853847
<xmp class='lang-javascript'>
854848
// Inside AnimationWorkletGlobalScope.
855-
registerAnimator('twitter-header', class HeaderAnimator extends StatelessAnimator {
849+
registerAnimator('twitter-header', class HeaderAnimator {
856850
constructor(options) {
857851
this.timing_ = new CubicBezier('ease-out');
858852
}
@@ -920,7 +914,7 @@ fastParallax.play();
920914

921915
<xmp class='lang-javascript'>
922916
// Inside AnimationWorkletGlobalScope.
923-
registerAnimator('parallax', class ParallaxAnimator extends StatelessAnimator {
917+
registerAnimator('parallax', class ParallaxAnimator {
924918
constructor(options) {
925919
this.rate_ = options.rate;
926920
}

0 commit comments

Comments
 (0)