Skip to content

Commit

Permalink
add more tests for thenable and tunable
Browse files Browse the repository at this point in the history
  • Loading branch information
legomushroom committed Apr 4, 2016
1 parent 1c41ec9 commit b3cfa9e
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 76 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mojs",
"description": "motion graphics toolbelt for the web",
"version": "0.214.1",
"version": "0.214.2",
"license": "MIT",
"homepage": "https://github.com/legomushroom/mojs",
"authors": [
Expand Down
49 changes: 28 additions & 21 deletions build/mo.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,12 @@
}, {
key: '_update',
value: function _update(time, timelinePrevTime, wasYoyo, onEdge) {
this._o.isIt && console.log('time: ' + time + ', timelinePrevTime: ' + timelinePrevTime + ', wasYoyo: ' + wasYoyo + ', onEdge: ' + onEdge + ' ');
var p = this._props;
// if we don't the _prevTime thus the direction we are heading to,
// but prevTime was passed thus we are child of a Timeline
// set _prevTime to passed one and pretent that there was unknown
// update to not to block start/complete callbacks
this._o.isIt && console.log('prevTime: ' + this._prevTime + ', timelinePrevTime: ' + timelinePrevTime);
if (this._prevTime == null && timelinePrevTime != null) {
this._o.isIt && console.log('setting the _prevTime to prevTime and _wasUknownUpdate');
this._prevTime = timelinePrevTime;
this._wasUknownUpdate = true;
}
Expand Down Expand Up @@ -648,7 +645,6 @@

this._setProgress(isYoyo ? 0 : 1, time, isYoyo);
this._repeatComplete(time, isYoyo);
this._o.isIt && console.log('h3');
this._complete(time, isYoyo);
}
// if was active and went to - inactive area "-"
Expand Down Expand Up @@ -698,7 +694,6 @@
this._isRepeatCompleted = false;
}
this._repeatComplete(time, isYoyo);
this._o.isIt && console.log('h4');
return this._complete(time, isYoyo);
}

Expand Down Expand Up @@ -786,7 +781,6 @@
// we have handled the case in this._wasUknownUpdate
// block so filter that
if (prevT === TCount && !this._wasUknownUpdate) {
this._o.isIt && console.log('h6');
this._complete(time, isYoyo);
this._repeatComplete(time, isYoyo);
this._firstUpdate(time, isYoyo);
Expand Down Expand Up @@ -984,7 +978,6 @@
if (this._isCompleted) {
return;
}
this._o.isIt && console.log('_complete!');
var p = this._props;
if (p.onComplete != null && typeof p.onComplete === 'function') {
p.onComplete.call(p.callbacksContext || this, time > this._prevTime, isYoyo);
Expand Down Expand Up @@ -1489,6 +1482,10 @@
this._o.isSwirl = this._props.isSwirl;
this._o.radius = 0;

// save timeline options and remove from _o
// cuz the master swirl should not get them
this._saveTimelineOptions(this._o);

this.masterSwirl = new _swirl2.default(this._o);
this._masterSwirls = [this.masterSwirl];

Expand All @@ -1512,6 +1509,19 @@
this._swirls = { 0: pack };
this._setSwirlDuration(this.masterSwirl, this._calcPackTime(pack));
}
/*
Method to save timeline options to _timelineOptions
and delete the property on the object.
@private
@param {Object} The object to save the timeline options from.
*/

}, {
key: '_saveTimelineOptions',
value: function _saveTimelineOptions(o) {
this._timelineOptions = o.timeline;
delete o.timeline;
}
/*
Method to calculate total time of array of
concurrent tweens.
Expand Down Expand Up @@ -1740,6 +1750,8 @@
}, {
key: '_makeTimeline',
value: function _makeTimeline() {
// restore timeline options that were deleted in _render method
this._o.timeline = this._timelineOptions;
(0, _get3.default)((0, _getPrototypeOf2.default)(Burst.prototype), '_makeTimeline', this).call(this);
this.timeline.add(this.masterSwirl, this._swirls[0]);
}
Expand Down Expand Up @@ -3901,7 +3913,7 @@

for (var key in end) {

/* !COVER! */
// just copy parent option
if (key == 'parent') {
o[key] = end[key];
continue;
Expand Down Expand Up @@ -4148,10 +4160,8 @@
value: function _transformHistory(o) {
for (var key in o) {
var value = o[key];
// !COVER!
if (key === 'childOptions') {
continue;
}
// don't transform for childOptions
// if ( key === 'childOptions' ) { continue; }
this._transformHistoryFor(key, this._preparsePropValue(key, value));
}
}
Expand Down Expand Up @@ -8010,21 +8020,22 @@
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

window.mojs = {
revision: '0.214.1', isDebug: true, helpers: _h2.default,
revision: '0.214.2', 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
};

// TODO:
/*
cover in thenable
cover in tunable
module names
timeline: {} for transit and burst after tune
callbacksContext for the masterSwirl
add onPlaybackStart, onPlaybackStop,
onPlaybackFinish methods to support mojs-player
perf optimizations.
--
add target instead of parent.
module names
swirls in then chains for x/y
parse rand(stagger(20, 10), 20) values
percentage for radius
Expand All @@ -8033,10 +8044,6 @@
mojs.h = mojs.helpers;
mojs.delta = mojs.h.delta;

// rangeSliderEl.addEventListener('input', function () {
// tr.setProgress( rangeSliderEl.value/1000 );
// });

// ### istanbul ignore next ###
if (true) {
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function () {
Expand Down
12 changes: 5 additions & 7 deletions build/mo.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/mo-js/0.174.4/mo.min.js"></script> -->

<input type="range" min="100" max="5000" value="1000" style="width: 500px; margin-top: 200px; margin-left: 200px;" id="js-speed-slider">

<input type="range" min="0" max="1000" value="0" style="width: 500px; margin-top: 200px; margin-left: 200px;" id="js-range-slider">

<script src="build/mo.js"></script>
</body>
</html>
18 changes: 17 additions & 1 deletion js/burst.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ class Burst extends Tunable {
this._o.isWithShape = false;
this._o.isSwirl = this._props.isSwirl;
this._o.radius = 0;


// save timeline options and remove from _o
// cuz the master swirl should not get them
this._saveTimelineOptions( this._o );

this.masterSwirl = new Swirl( this._o );
this._masterSwirls = [ this.masterSwirl ];

Expand All @@ -212,6 +216,16 @@ class Burst extends Tunable {
this._swirls = { 0: pack };
this._setSwirlDuration( this.masterSwirl, this._calcPackTime(pack) );
}
/*
Method to save timeline options to _timelineOptions
and delete the property on the object.
@private
@param {Object} The object to save the timeline options from.
*/
_saveTimelineOptions ( o ) {
this._timelineOptions = o.timeline;
delete o.timeline;
}
/*
Method to calculate total time of array of
concurrent tweens.
Expand Down Expand Up @@ -394,6 +408,8 @@ class Burst extends Tunable {
@override @ Tweenable
*/
_makeTimeline () {
// restore timeline options that were deleted in _render method
this._o.timeline = this._timelineOptions;
super._makeTimeline();
this.timeline.add( this.masterSwirl, this._swirls[0] );
}
Expand Down
16 changes: 6 additions & 10 deletions js/mojs.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ import tweener from './tween/tweener';
import easing from './easing/easing';

window.mojs = {
revision: '0.214.1', isDebug: true, helpers: h,
revision: '0.214.2', isDebug: true, helpers: h,
Transit, Swirl, Burst, stagger, Spriter, MotionPath,
Tween, Timeline, Tweenable, Thenable, Tunable, Module,
tweener, easing, shapesMap
}

// TODO:
/*
cover in thenable
cover in tunable
module names
timeline: {} for transit and burst after tune
callbacksContext for the masterSwirl
add onPlaybackStart, onPlaybackStop,
onPlaybackFinish methods to support mojs-player
perf optimizations.
--
add target instead of parent.
module names
swirls in then chains for x/y
parse rand(stagger(20, 10), 20) values
percentage for radius
Expand All @@ -40,11 +41,6 @@ window.mojs = {
mojs.h = mojs.helpers;
mojs.delta = mojs.h.delta;

// rangeSliderEl.addEventListener('input', function () {
// tr.setProgress( rangeSliderEl.value/1000 );
// });



// ### istanbul ignore next ###
if ( (typeof define === "function") && define.amd ) {
Expand Down
2 changes: 1 addition & 1 deletion js/thenable.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Thenable extends Tweenable {

for (var key in end) {

/* !COVER! */
// just copy parent option
if ( key == 'parent' ) {
o[key] = end[key];
continue;
Expand Down
4 changes: 2 additions & 2 deletions js/tunable.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class Tuneable extends Thenable {
_transformHistory ( o ) {
for (var key in o) {
var value = o[key];
// !COVER!
if ( key === 'childOptions' ) { continue; }
// don't transform for childOptions
// if ( key === 'childOptions' ) { continue; }
this._transformHistoryFor( key, this._preparsePropValue( key, value ) );
}
}
Expand Down
7 changes: 0 additions & 7 deletions js/tween/tween.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,12 @@ class Tween extends Module {
1 = edge jump in positive direction.
*/
_update ( time, timelinePrevTime, wasYoyo, onEdge ) {
this._o.isIt && console.log(`time: ${time}, timelinePrevTime: ${timelinePrevTime}, wasYoyo: ${wasYoyo}, onEdge: ${onEdge} `);
var p = this._props;
// if we don't the _prevTime thus the direction we are heading to,
// but prevTime was passed thus we are child of a Timeline
// set _prevTime to passed one and pretent that there was unknown
// update to not to block start/complete callbacks
this._o.isIt && console.log(`prevTime: ${this._prevTime}, timelinePrevTime: ${timelinePrevTime}`);
if ( this._prevTime == null && timelinePrevTime != null ) {
this._o.isIt && console.log('setting the _prevTime to prevTime and _wasUknownUpdate');
this._prevTime = timelinePrevTime;
this._wasUknownUpdate = true;
}
Expand Down Expand Up @@ -451,7 +448,6 @@ class Tween extends Module {

this._setProgress( (isYoyo) ? 0 : 1, time, isYoyo );
this._repeatComplete( time, isYoyo );
this._o.isIt && console.log('h3');
this._complete( time, isYoyo );
}
// if was active and went to - inactive area "-"
Expand Down Expand Up @@ -496,7 +492,6 @@ class Tween extends Module {
this._setProgress( (isYoyo ? 0 : 1), time, isYoyo );
if ( time > this._prevTime ) { this._isRepeatCompleted = false; }
this._repeatComplete( time, isYoyo );
this._o.isIt && console.log('h4');
return this._complete( time, isYoyo );
}

Expand Down Expand Up @@ -582,7 +577,6 @@ class Tween extends Module {
// we have handled the case in this._wasUknownUpdate
// block so filter that
if ( prevT === TCount && !this._wasUknownUpdate ) {
this._o.isIt && console.log('h6');
this._complete( time, isYoyo );
this._repeatComplete( time, isYoyo );
this._firstUpdate( time, isYoyo );
Expand Down Expand Up @@ -755,7 +749,6 @@ class Tween extends Module {
*/
_complete ( time, isYoyo ) {
if ( this._isCompleted ) { return; }
this._o.isIt && console.log('_complete!');
var p = this._props;
if (p.onComplete != null && typeof p.onComplete === 'function') {
p.onComplete.call( p.callbacksContext || this, time > this._prevTime, isYoyo );
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mo-js",
"description": "motion graphics toolbelt for the web",
"version": "0.214.1",
"version": "0.214.2",
"license": "MIT",
"private": false,
"scripts": {
Expand Down
23 changes: 22 additions & 1 deletion spec/burst.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ describe 'Burst ->', ->
burst = new Burst opts
expect(burst.masterSwirl._o.radius).toBe 0

it 'should call _saveTimelineOptions method', ->
opts = {}
b = new Burst opts
spyOn b, '_saveTimelineOptions'
b._render()
expect(b._saveTimelineOptions).toHaveBeenCalledWith b._o

it 'should call _renderSwirls method', ->
opts = {}
burst = new Burst opts
Expand Down Expand Up @@ -217,6 +224,13 @@ describe 'Burst ->', ->
expect(mojs.Tweenable.prototype._makeTween).not.toHaveBeenCalled()

describe '_makeTimeline method ->', ->

it 'should restore timeline options on _o', ->
timeline = {}
bs = new Burst timeline: timeline
bs._makeTimeline()
expect(bs._o.timeline).toBe timeline

it 'should call super', ->
bs = new Burst
spyOn mojs.Tweenable::, '_makeTimeline'
Expand Down Expand Up @@ -707,7 +721,14 @@ describe 'Burst ->', ->
for key of b._defaults
expect(o[key]).toBe 1


describe '_saveTimelineOptions method ->', ->
it 'should save timelone options to _timelineOptions', ->
b = new Burst
timeline = {}
opts = { timeline: timeline }
b._saveTimelineOptions opts
expect( b._timelineOptions ).toBe timeline
expect( opts.timeline ).not.toBeDefined()



Expand Down

0 comments on commit b3cfa9e

Please sign in to comment.