Skip to content

Commit

Permalink
Minor changes to fix issues with replaying
Browse files Browse the repository at this point in the history
When replaying an animation the completed state is never reached as the
property is not reset after `play()` is called subsequent times. I've
changed the `play()` call to reset this value to `false`.

I also looked into the issues reported for Promises and realized we
could do a better job when resetting it. This is where I identified the
previous problem.

I do not believe any API changes will break and I've reviewed the
examples and everything looks fine.

Closes the following issues:

- juliangarnier#373
- juliangarnier#378
- juliangarnier#392

And the following redundant PR:

- juliangarnier#408
  • Loading branch information
tbranyen committed Jan 15, 2019
1 parent abe2714 commit 61e0d8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions documentation/assets/js/anime/anime.2.2.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,14 +707,16 @@

let resolve = null;

function makePromise() {
return window.Promise && new Promise(_resolve => resolve = _resolve);
function makePromise(instance) {
const promise = window.Promise && new Promise(_resolve => resolve = _resolve);
instance.finished = promise;
return promise;
}

let promise = makePromise();

let instance = createNewInstance(params);

let promise = makePromise(instance);

function toggleInstanceDirection() {
instance.reversed = !instance.reversed;
}
Expand Down Expand Up @@ -855,7 +857,7 @@
setCallback('complete');
if ('Promise' in window) {
resolve();
promise = makePromise();
promise = makePromise(instance);
}
}
}
Expand Down Expand Up @@ -899,6 +901,7 @@
instance.play = function() {
if (!instance.paused) return;
instance.paused = false;
instance.completed = false;
startTime = 0;
lastTime = adjustTime(instance.currentTime);
activeInstances.push(instance);
Expand All @@ -917,8 +920,6 @@
instance.play();
}

instance.finished = promise;

instance.reset();

if (instance.autoplay) instance.play();
Expand Down
Loading

0 comments on commit 61e0d8b

Please sign in to comment.