Skip to content

Commit

Permalink
tween: _prevTime now always undefined instead of null
Browse files Browse the repository at this point in the history
  • Loading branch information
legomushroom committed Apr 28, 2016
1 parent 0d98673 commit 9fd8bcb
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 63 deletions.
2 changes: 1 addition & 1 deletion bower.json
@@ -1,7 +1,7 @@
{
"name": "mojs",
"description": "motion graphics toolbelt for the web",
"version": "0.226.3",
"version": "0.226.6",
"license": "MIT",
"homepage": "https://github.com/legomushroom/mojs",
"authors": [
Expand Down
14 changes: 6 additions & 8 deletions build/mo.js
Expand Up @@ -467,10 +467,8 @@


Tween.prototype._vars = function _vars() {
// call _vars @ Module
// super._vars();
this.progress = 0;
this._prevTime = null;
this._prevTime = undefined;
this._progressTime = 0;
this._negativeShift = 0;
this._state = 'stop';
Expand Down Expand Up @@ -614,7 +612,7 @@
}
// reset the _prevTime - drop one frame to undestand
// where we are heading
this._prevTime = null;
this._prevTime = undefined;
}
// if in active area and not ended - save progress time
// for pause/play purposes.
Expand All @@ -636,7 +634,7 @@
// We need to know what direction we are heading to,
// so if we don't have the previous update value - this is very first
// update, - skip it entirely and wait for the next value
if (this._prevTime === null) {
if (this._prevTime == null) {
this._prevTime = time;
this._wasUknownUpdate = true;
return false;
Expand Down Expand Up @@ -3391,9 +3389,9 @@
// cache the current tween
var tween = this.tweens[i];
if (tween && tween._update(time) === true) {
this.remove(i);
this.remove(tween);
tween._onTweenerFinish();
tween._prevTime = null;
tween._prevTime = undefined;
}
}
};
Expand Down Expand Up @@ -7812,7 +7810,7 @@
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var mojs = {
revision: '0.226.3', isDebug: true, helpers: _h2.default,
revision: '0.226.6', isDebug: true, helpers: _h2.default,
Transit: _transit2.default, Swirl: _swirl2.default, Burst: _burst2.default, stagger: _stagger2.default, Spriter: _spriter2.default, MotionPath: _motionPath2.default,
Tween: _tween2.default, Timeline: _timeline2.default, Tweenable: _tweenable2.default, Thenable: _thenable2.default, Tunable: _tunable2.default, Module: _module2.default,
tweener: _tweener2.default, easing: _easing2.default, shapesMap: _shapesMap2.default
Expand Down
9 changes: 4 additions & 5 deletions build/mo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/mojs.babel.js
Expand Up @@ -17,7 +17,7 @@ import tweener from './tween/tweener';
import easing from './easing/easing';

var mojs = {
revision: '0.226.3', isDebug: true, helpers: h,
revision: '0.226.6', isDebug: true, helpers: h,
Transit, Swirl, Burst, stagger, Spriter, MotionPath,
Tween, Timeline, Tweenable, Thenable, Tunable, Module,
tweener, easing, shapesMap
Expand Down
12 changes: 5 additions & 7 deletions js/tween/tween.babel.js
Expand Up @@ -313,11 +313,9 @@ class Tween extends Module {
@private
*/
_vars () {
// call _vars @ Module
// super._vars();
this.progress = 0;
this._prevTime = null;
this._progressTime = 0;
this.progress = 0;
this._prevTime = undefined;
this._progressTime = 0;
this._negativeShift = 0;
this._state = 'stop';
// if negative delay was specified,
Expand Down Expand Up @@ -451,7 +449,7 @@ class Tween extends Module {
}
// reset the _prevTime - drop one frame to undestand
// where we are heading
this._prevTime = null;
this._prevTime = undefined;
}
// if in active area and not ended - save progress time
// for pause/play purposes.
Expand All @@ -470,7 +468,7 @@ class Tween extends Module {
// We need to know what direction we are heading to,
// so if we don't have the previous update value - this is very first
// update, - skip it entirely and wait for the next value
if ( this._prevTime === null ) {
if ( this._prevTime == null ) {
this._prevTime = time;
this._wasUknownUpdate = true;
return false;
Expand Down
4 changes: 2 additions & 2 deletions js/tween/tweener.babel.js
Expand Up @@ -41,9 +41,9 @@ class Tweener {
// cache the current tween
var tween = this.tweens[i];
if ( tween && tween._update(time) === true ) {
this.remove(i);
this.remove( tween );
tween._onTweenerFinish();
tween._prevTime = null;
tween._prevTime = undefined;
}
}
}
Expand Down
56 changes: 28 additions & 28 deletions karma.conf.js
Expand Up @@ -88,33 +88,33 @@ module.exports = function(config) {
],
// list of files to exclude
exclude: [
'build/h.js',
'spec/h.js',
'build/transit.js',
'spec/transit.js',
'build/swirl.js',
'spec/swirl.js',
'build/burst.js',
'spec/burst.js',
// 'build/h.js',
// 'spec/h.js',
// 'build/transit.js',
// 'spec/transit.js',
// 'build/swirl.js',
// 'spec/swirl.js',
// 'build/burst.js',
// 'spec/burst.js',

'build/module.js',
'spec/module.js',
'build/tween/tweenable.js',
'spec/tween/tweenable.js',
'build/tunable.js',
'spec/tunable.js',
'build/thenable.js',
'spec/thenable.js',
'build/runable.js',
'spec/runable.js',
// 'build/module.js',
// 'spec/module.js',
// 'build/tween/tweenable.js',
// 'spec/tween/tweenable.js',
// 'build/tunable.js',
// 'spec/tunable.js',
// 'build/thenable.js',
// 'spec/thenable.js',
// 'build/runable.js',
// 'spec/runable.js',

'build/spriter.js',
'spec/spriter.js',
'build/stagger.js',
'spec/stagger.js',
// 'build/spriter.js',
// 'spec/spriter.js',
// 'build/stagger.js',
// 'spec/stagger.js',

'build/easing/easing.js',
'spec/easing/easing.js',
// 'build/easing/easing.js',
// 'spec/easing/easing.js',

// 'build/tween/timeline.js',
// 'spec/tween/timeline.js',
Expand All @@ -123,10 +123,10 @@ module.exports = function(config) {
// 'build/tween/tweener.js',
// 'spec/tween/tweener.js',

'build/motion-path.js',
'spec/motion-path.js',
'build/bits/*.js',
'spec/bits/*.js'
// 'build/motion-path.js',
// 'spec/motion-path.js',
// 'build/bits/*.js',
// 'spec/bits/*.js'
],

// preprocess matching files before serving them to the browser
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "mo-js",
"description": "motion graphics toolbelt for the web",
"version": "0.226.3",
"version": "0.226.6",
"license": "MIT",
"private": false,
"scripts": {
Expand Down
16 changes: 14 additions & 2 deletions spec/tween/tween.coffee
Expand Up @@ -320,6 +320,18 @@ describe 'Tween ->', ->
time = t._props.startTime + shift
t._update time
expect(t._prevTime).toBeCloseTo (t._props.endTime - t._progressTime), 3
it 'should skip frame with `undefined` too', ->
duration = 1000
t = new Tween(duration: duration)
t._setStartTime()
t._wasUknownUpdate = false
t._prevTime = undefined

shift = 200
time = t._props.startTime + shift
t._update time
expect(t._wasUknownUpdate).toBe true
# expect(t._prevTime).toBeCloseTo (t._props.endTime - t._progressTime), 3
it 'should recalculate time for speed if defined', ->
delay = 50; duration = 1000
speed = 2
Expand Down Expand Up @@ -7013,10 +7025,10 @@ describe 'Tween ->', ->
time = tw._resumeTime - Math.abs(0) - tw._progressTime
expect(tw._setStartTime).toHaveBeenCalledWith time, false
describe '_prevTime normalization ->', ->
it 'should not set _prevTime if it is null', ()->
it 'should not set _prevTime if it is undefined', ()->
tw = new Tween
tw._setResumeTime( 'play' )
expect(tw._prevTime).toBe null
expect(tw._prevTime).toBe undefined
it 'should set prevTime to _normPrevTimeForward() if `play`', ->
tw = new Tween
tw._prevTime = 200
Expand Down
18 changes: 16 additions & 2 deletions spec/tween/tween.js
Expand Up @@ -512,6 +512,20 @@
t._update(time);
return expect(t._prevTime).toBeCloseTo(t._props.endTime - t._progressTime, 3);
});
it('should skip frame with `undefined` too', function() {
var duration, shift, t, time;
duration = 1000;
t = new Tween({
duration: duration
});
t._setStartTime();
t._wasUknownUpdate = false;
t._prevTime = void 0;
shift = 200;
time = t._props.startTime + shift;
t._update(time);
return expect(t._wasUknownUpdate).toBe(true);
});
it('should recalculate time for speed if defined', function() {
var delay, duration, speed, startPoint, t, time;
delay = 50;
Expand Down Expand Up @@ -7281,11 +7295,11 @@
return expect(tw._setStartTime).toHaveBeenCalledWith(time, false);
});
return describe('_prevTime normalization ->', function() {
it('should not set _prevTime if it is null', function() {
it('should not set _prevTime if it is undefined', function() {
var tw;
tw = new Tween;
tw._setResumeTime('play');
return expect(tw._prevTime).toBe(null);
return expect(tw._prevTime).toBe(void 0);
});
it('should set prevTime to _normPrevTimeForward() if `play`', function() {
var tw;
Expand Down
6 changes: 3 additions & 3 deletions spec/tween/tweener.coffee
Expand Up @@ -142,10 +142,10 @@ describe 'Tweener ->', ->
expect(t.tweens[0]).toBe tw
spyOn(t, 'remove').and.callThrough()
t._update time = performance.now() + 200
expect(t.remove).toHaveBeenCalledWith 0
expect(t.remove).toHaveBeenCalledWith tw
expect(t.tweens[0]).not.toBeDefined()

it 'should set tween\'s _prevTime to null if ended', (dfr)->
it 'should set tween\'s _prevTime to undefined if ended', (dfr)->
tw = new Tween duration: 100
tw._setStartTime()
t.add tw
Expand All @@ -154,7 +154,7 @@ describe 'Tweener ->', ->
startTime = performance.now()

setTimeout ->
expect(tw._prevTime).toBe null
expect(tw._prevTime).toBe undefined
dfr()
, 400

Expand Down
6 changes: 3 additions & 3 deletions spec/tween/tweener.js
Expand Up @@ -205,10 +205,10 @@
expect(t.tweens[0]).toBe(tw);
spyOn(t, 'remove').and.callThrough();
t._update(time = performance.now() + 200);
expect(t.remove).toHaveBeenCalledWith(0);
expect(t.remove).toHaveBeenCalledWith(tw);
return expect(t.tweens[0]).not.toBeDefined();
});
it('should set tween\'s _prevTime to null if ended', function(dfr) {
it('should set tween\'s _prevTime to undefined if ended', function(dfr) {
var startTime, tw;
tw = new Tween({
duration: 100
Expand All @@ -219,7 +219,7 @@
spyOn(t, 'remove').and.callThrough();
startTime = performance.now();
return setTimeout(function() {
expect(tw._prevTime).toBe(null);
expect(tw._prevTime).toBe(void 0);
return dfr();
}, 400);
});
Expand Down

0 comments on commit 9fd8bcb

Please sign in to comment.