Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-animationworklet] Change state to be a function instead of getter #866

Merged
merged 3 commits into from
Mar 11, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions css-animationworklet/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ interface StatelessAnimator {
<div class='note'>
This is how the class should look.
<pre class='lang-javascript'>
class FooAnimator extends StatelessAnimator{
class FooAnimator extends StatelessAnimator {
constructor(options) {
// Called when a new animator is instantiated.
}
Expand Down Expand Up @@ -253,21 +253,21 @@ effect is mutable only in a certain thread). Animation worklet guarantees that a
instance's state is maintained even if the instance is respawned in a different global scope.

The basic mechanism for maintaining the state is that the animation worklet snapshots the local
state that is exposed via {{StatefulAnimator/state}} attribute and then reifies it at a later time
to be passed into the constructor when the animator instance is respawned in a potentially different
global scope. This processes is specified is details in <a>migrate an animator instance</a>
algorithm.
state that is exposed via {{StatefulAnimator/state}} function and then reifies it so that it can be
majido marked this conversation as resolved.
Show resolved Hide resolved
passed into the constructor when the animator instance is respawned at a later time in a potentially
different global scope. The <a>migrate an animator instance</a> algorithm specifies this process in
details.

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

<xmp class='idl'>
[Exposed=AnimationWorklet, Global=AnimationWorklet,
Constructor (optional any options, optional any state)]
interface StatefulAnimator {
attribute any state;
any state();
};
</xmp>

Expand All @@ -284,7 +284,7 @@ interface StatefulAnimator {
// Animation frame logic goes here and can rely on this.currentVelocity.
this.currentVelocity += 0.1;
}
get state {
state() {
// The returned object should be serializable using structured clonable algorithm.
return {
velocity: this.currentVelocity;
Expand Down Expand Up @@ -534,8 +534,9 @@ To <dfn>migrate an animator instance</dfn> from one {{WorkletGlobalScope}} to an

4. If |stateful| is <b>false</b> then abort the following steps.

5. Let |state| be the result of <a>Get</a>(|instance|, "state"). If any exception is thrown,
rethrow the exception and abort the following steps.
5. Let |state| be the result of <a>Invoke</a> |stateFunction| with |instance| as the
<a>callback this value</a>. If any exception is thrown, rethrow the exception and abort
the following steps.

6. Set |serializedState| to be the result of <a>StructuredSerialize</a>(|state|).
If any exception is thrown, then abort the following steps.
Expand Down