[web-animations] AnimationPlayer.ready confusion

Hi, everyone.

It seems that there's an issue in Example 1 from section 3.5.8. The  
current ready promise
(http://w3c.github.io/web-animations/#the-current-ready-promise). Let's  
consider it.

player.pause();
player.ready.then(function() {
   // Displays 'running'
   alert(player.playState);
});
player.play();

Depending on implementation I can predict two different behaviors:

player.pause(); // => let's assume that player is not ready and schedules
// the pending pause task, so player.ready promise is pending

player.ready.then(function() {
     // Displays 'running'
     alert(player.playState);
});

// let's assume that player is still not ready when player.play() starts
player.play();
// executes 'play a player' procedure
// http://w3c.github.io/web-animations/#playing-a-player-section
// pending pause task is canceled
// player.ready promise object is reused
// so when player is ready, 'running' will be displayed.


Another option:

player.pause(); // => let's assume that player is immediately ready,
// so pending pause task is not scheduled, all necessary actions are  
immediately executed
// player.ready promise is fulfilled

player.ready.then(function() { // => because player.ready promise is  
fulfilled,
// the function is executed immediately, 'paused' is displayed.
     alert(player.playState);
});

player.play();
// executes 'play a player' procedure
// http://w3c.github.io/web-animations/#playing-a-player-section
// there is no pending task
// player.ready promise is replaced with new one, which has no handler


So depending on implementation there can be at least two different
results. It seems that this is part of more general problem.

1. AnimationPlayer.ready serves for several methods play(), pause(),  
reverse(), cancel().
So there is no way to predict in response to which method call the promise
handler function is called.

2. Methods play(), pause(), reverse() can replace AnimationPlayer.ready
with a new Promise object. There is no way to predict whether
AnimationPlayer.ready will be replaced or not, because it depends on
whether the player has pending tasks or not.

For example, how to get some function called in response to some method
call (pause() or play() or reverse())? I.e. I call, for example, method
pause() and would like to get my handlePause() function called exactly
when player pause operation is complete. Currently, the only way to do
that is to use code like this:

player.ready.then(function() {
     if (player.playState === 'paused') {
         handlePause()
     }
});

But this is not enough. As it was demonstrated above, the handler function
can be called later in response to other method call, so there might be no
call to handlePause() at all after call to player.pause().

I find this problem very confusing.

Is it possible to change the specification, that each method
(play, pause, reverse, finish) return unique Promise object related
to the method. So the following promise-like code could be possible:

player.pause().then(handlePause, rejected);
player.play().then(handlePlay, rejected);
player.finish().then(handleFinish, rejected);

Thanks,
Aleksei.

Received on Friday, 23 January 2015 11:02:50 UTC