Re: [css-houdini-drafts] [css-animationworklet] Verifying the StatefullAnimatior/StatelessAnimator superclass on prototype chain (#850)

To make the difference more clear. Here are the two choices:

### Currently specified - Use two separate superclasses

```
// The fact that this extends StatefulAnimator indicates this is a stateful.
// It still has to implement state() function.
registerAnimator('a', class Foo extends StatefulAnimator {
  constructor(options, state) {}
  animate(currentTime, effect) {}
  state() { return 'some state'; } 
});

registerAnimator('b', class Bar extends StatelessAnimator {
  constructor(options) {}
  animate(currentTime, effect) {}
});
```

Cons:
 - Two super classes (as opposed to mixin) makes its harder for authors to mix it with any existing class hierarchy they have. I suspect most will just have StatefulAnimator at the top of their class hierarchy which defeats the purpose.
- The author still has to implement state() function anyway. 
- More difficult to spec and implement


### New proposal - Use state function existence to differentiate
```js
registerAnimator('a', class Foo {
  constructor(options, state) {}
  animate(currentTime, effect) {}
  // The fact that there is a state getter indicates this is a stateful animator.
  state() { return 'some state'; } 
});

registerAnimator('b', class Bar {
  constructor(options) {}
  animate(currentTime, effect) {}
});
```

Pros:
 - No requirements on class hierarchy which allows a lot more flexibility 
 - Implementation of state function(satisfying the contract) is enough! 
 - Simpler to spec and implement 

Cons:
 - Having a superclass is nice e.g., we can add other methods that have meaningful default behavior (e.g., `pause`, `play`) but that only needs a single superclass `Animator` and also can be done later when it is needed.

-- 
GitHub Notification of comment by majido
Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/850#issuecomment-499851180 using your GitHub account

Received on Friday, 7 June 2019 11:30:29 UTC