Skip to content

Commit

Permalink
Minor fixes 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 Nov 10, 2018
1 parent 69131dc commit 85f60c8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions anime.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

0 comments on commit 85f60c8

Please sign in to comment.