From 85f60c84fe4a5e54c37a4e5b4cf29abfa3f2ddcf Mon Sep 17 00:00:00 2001 From: Tim Branyen Date: Fri, 9 Nov 2018 23:44:59 -0800 Subject: [PATCH] Minor fixes to fix issues with replaying 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: - https://github.com/juliangarnier/anime/issues/373 - https://github.com/juliangarnier/anime/issues/378 - https://github.com/juliangarnier/anime/issues/392 And the following redundant PR: - https://github.com/juliangarnier/anime/pull/408 --- anime.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/anime.js b/anime.js index 64730fac..d76712d1 100644 --- a/anime.js +++ b/anime.js @@ -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; } @@ -855,7 +857,7 @@ setCallback('complete'); if ('Promise' in window) { resolve(); - promise = makePromise(); + promise = makePromise(instance); } } } @@ -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); @@ -917,8 +920,6 @@ instance.play(); } - instance.finished = promise; - instance.reset(); if (instance.autoplay) instance.play();