Skip to content

Commit 148a97f

Browse files
author
daniel-lundin
committed
Re-added 'stop' command that got lost in the refactor
1 parent ed5f53f commit 148a97f

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

src/animation.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ function createAnimation(startState, endState, options, transformProperty) {
4141
stop() { stopped = true; },
4242
endState() { return endState; },
4343
isStopped() { return stopped; },
44-
isStarted() { return started; },
4544

4645
finish(callback) {
4746
manual = false;
@@ -108,7 +107,7 @@ function createAnimation(startState, endState, options, transformProperty) {
108107
manualValue = Math.min(Math.max(_manualValue, 0.0001), 1 + manualDelayFactor);
109108
},
110109

111-
updateCurrentTransform: function() {
110+
updateCurrentTransform() {
112111
var tweenValue = easer.getValue();
113112
if (manual) {
114113
var value = Math.max(0.00001, manualValue - manualDelayFactor);

src/engine.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ const Engine = {
138138
var animation;
139139
if (arg2 === 'attention') {
140140
animation = this.createAttentionAnimation(element, arg3);
141+
} else if (arg2 === 'stop') {
142+
return this.runningAnimations = this.runningAnimations.filter((animation) => {
143+
return element !== animation[0];
144+
});
141145
} else {
142146
animation = this.createAnimation(element, arg2);
143147
}

src/tests/animationTests.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const sinon = require('sinon');
4-
const chai = require('chai')
4+
const chai = require('chai');
55
const expect = chai.expect;
66
chai.use(require('chai-string'));
77
const createAnimation = require('../animation.js').createAnimation;
@@ -31,12 +31,10 @@ describe('animations', () => {
3131
animation.updateCurrentTransform.restore();
3232
});
3333

34-
it('should set started and call updateTransform for first tick', () => {
35-
expect(animation.isStarted()).to.not.be.ok;
34+
it('should call updateTransform for first tick', () => {
3635
sinon.assert.notCalled(animation.updateCurrentTransform);
3736

3837
animation.tick(100);
39-
expect(animation.isStarted()).to.be.ok;
4038
sinon.assert.calledOnce(animation.updateCurrentTransform);
4139
});
4240

src/tests/engineTests.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ describe('Engine', () => {
254254
expect(Engine.runningAnimations).to.have.length(1);
255255
});
256256

257+
it('should stop animation with \'stop\' command', () => {
258+
const element = {};
259+
Engine.runningAnimations = [[element, {}, {}]];
260+
261+
Engine.initializeAnimation(element, 'stop');
262+
263+
expect(Engine.runningAnimations).to.have.length(0);
264+
});
265+
257266
describe('manual animations', () => {
258267
beforeEach(() => {
259268
sinon.stub(Animation, 'createAttentionAnimation');

0 commit comments

Comments
 (0)