Skip to content

Commit 58db55f

Browse files
committed
fix(animation): don't trigger <done> when clearing animation
Previously we did not properly separate completion from clearing an animation; we would not properly be able to distinguish both, effectively always triggering the animation <done> effect, also when clearing a scope (i.e. because it was terminated). This change moves the control over individual animations to the animation service, and applies <done> only when the animation completes normally.
1 parent 10c82bc commit 58db55f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/animation/Animation.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Animation.prototype.createAnimation = function(connection, scope, done = noop) {
139139
const tokenGfx = this._createTokenGfx(group, scope);
140140

141141
const animation = new TokenAnimation(tokenGfx, connection.waypoints, this._randomize, () => {
142-
this._animations.delete(animation);
142+
this._clearAnimation(animation);
143143

144144
done();
145145
});
@@ -181,11 +181,17 @@ Animation.prototype.getAnimationSpeed = function() {
181181
Animation.prototype.clearAnimations = function(scope) {
182182
this.each(animation => {
183183
if (!scope || animation.scope === scope) {
184-
animation.remove();
184+
this._clearAnimation(animation);
185185
}
186186
});
187187
};
188188

189+
Animation.prototype._clearAnimation = function(animation) {
190+
animation.remove();
191+
192+
this._animations.delete(animation);
193+
};
194+
189195
Animation.prototype._createTokenGfx = function(group, scope) {
190196
const parent = svgCreate(this._getTokenSVG(scope).trim());
191197

@@ -320,7 +326,7 @@ TokenAnimation.prototype.tick = function(tElapsed) {
320326

321327
// completed
322328
if (!part) {
323-
return this.remove();
329+
return this.completed();
324330
}
325331

326332
const segmentTime = t - part.startTime;
@@ -405,12 +411,14 @@ TokenAnimation.prototype.hide = function() {
405411
svgAttr(this.gfx, 'display', 'none');
406412
};
407413

414+
TokenAnimation.prototype.completed = function() {
415+
this.done();
416+
};
417+
408418
TokenAnimation.prototype.remove = function() {
409419
this.pause();
410420

411421
svgRemove(this.gfx);
412-
413-
this.done();
414422
};
415423

416424
TokenAnimation.prototype.setSpeed = function(speed) {

0 commit comments

Comments
 (0)