nanotween
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -26,3 +26,5 @@ var uptime = require('nanouptime'); | ||
duration: 0, | ||
easing: null, | ||
easing: function(x) { | ||
return x | ||
}, | ||
reversed: false, | ||
@@ -39,2 +41,13 @@ converters: [] | ||
var self = this; | ||
function remaining() { | ||
return { | ||
progress: self.state.progress, | ||
value: self.state.value, | ||
remaining: self.state.repeats + 1, | ||
completed: self._options.repeats - self.state.repeats - 1 | ||
} | ||
} | ||
this.bus = new NanoEvents(); | ||
@@ -61,3 +74,2 @@ | ||
this._options.repeats = repeat; | ||
this.state.repeats = repeat - 1; | ||
return this | ||
@@ -84,7 +96,3 @@ }; | ||
this.state.progress = progress; | ||
var easing = this._options.easing | ||
? this._options.easing | ||
: function(x) { | ||
return x | ||
}; | ||
var easing = this._options.easing; | ||
easing.reverse = easing.reverse || easing; | ||
@@ -102,2 +110,3 @@ var value = this._options.reversed | ||
this.set(0); | ||
this.state.repeats = this._options.repeats - 1; | ||
this.state.isRunning = true; | ||
@@ -110,2 +119,3 @@ this.bus.emit('start'); | ||
this.set(1); | ||
this.state.repeats = 0; | ||
this.state.isRunning = false; | ||
@@ -116,16 +126,9 @@ this.bus.emit('stop'); | ||
this.complete = function(emit) { | ||
emit = emit === void 0 ? true : emit; | ||
this.complete = function() { | ||
if (this.state.repeats > 0) { | ||
this.state.repeats--; | ||
this.set(1); | ||
setTimeout(() => { | ||
if (emit) { | ||
this.bus.emit('step', { | ||
value: this.state.value, | ||
remaining: this.state.repeats + 1, | ||
completed: this._options.repeats - this.state.repeats - 1 | ||
}); | ||
} | ||
this.set(0); | ||
setTimeout(function() { | ||
self.bus.emit('step', remaining()); | ||
self.set(0); | ||
}, 0); | ||
@@ -135,3 +138,5 @@ } else { | ||
this.set(1); | ||
if (emit) setTimeout(() => this.bus.emit('complete'), 0); | ||
setTimeout(function() { | ||
self.bus.emit('complete'); | ||
}, 0); | ||
} | ||
@@ -142,3 +147,3 @@ }; | ||
this.state.isRunning = true; | ||
this.bus.emit('play'); | ||
this.bus.emit('play', remaining()); | ||
return this | ||
@@ -149,3 +154,3 @@ }; | ||
this.state.isRunning = false; | ||
this.bus.emit('pause'); | ||
this.bus.emit('pause', remaining()); | ||
return this | ||
@@ -152,0 +157,0 @@ }; |
45
index.js
@@ -26,3 +26,5 @@ import uptime from 'nanouptime' | ||
duration: 0, | ||
easing: null, | ||
easing: function(x) { | ||
return x | ||
}, | ||
reversed: false, | ||
@@ -39,2 +41,13 @@ converters: [] | ||
var self = this | ||
function remaining() { | ||
return { | ||
progress: self.state.progress, | ||
value: self.state.value, | ||
remaining: self.state.repeats + 1, | ||
completed: self._options.repeats - self.state.repeats - 1 | ||
} | ||
} | ||
this.bus = new NanoEvents() | ||
@@ -61,3 +74,2 @@ | ||
this._options.repeats = repeat | ||
this.state.repeats = repeat - 1 | ||
return this | ||
@@ -85,6 +97,2 @@ } | ||
var easing = this._options.easing | ||
? this._options.easing | ||
: function(x) { | ||
return x | ||
} | ||
easing.reverse = easing.reverse || easing | ||
@@ -102,2 +110,3 @@ var value = this._options.reversed | ||
this.set(0) | ||
this.state.repeats = this._options.repeats - 1 | ||
this.state.isRunning = true | ||
@@ -110,2 +119,3 @@ this.bus.emit('start') | ||
this.set(1) | ||
this.state.repeats = 0 | ||
this.state.isRunning = false | ||
@@ -116,16 +126,9 @@ this.bus.emit('stop') | ||
this.complete = function(emit) { | ||
emit = emit === void 0 ? true : emit | ||
this.complete = function() { | ||
if (this.state.repeats > 0) { | ||
this.state.repeats-- | ||
this.set(1) | ||
setTimeout(() => { | ||
if (emit) { | ||
this.bus.emit('step', { | ||
value: this.state.value, | ||
remaining: this.state.repeats + 1, | ||
completed: this._options.repeats - this.state.repeats - 1 | ||
}) | ||
} | ||
this.set(0) | ||
setTimeout(function() { | ||
self.bus.emit('step', remaining()) | ||
self.set(0) | ||
}, 0) | ||
@@ -135,3 +138,5 @@ } else { | ||
this.set(1) | ||
if (emit) setTimeout(() => this.bus.emit('complete'), 0) | ||
setTimeout(function() { | ||
self.bus.emit('complete') | ||
}, 0) | ||
} | ||
@@ -142,3 +147,3 @@ } | ||
this.state.isRunning = true | ||
this.bus.emit('play') | ||
this.bus.emit('play', remaining()) | ||
return this | ||
@@ -149,3 +154,3 @@ } | ||
this.state.isRunning = false | ||
this.bus.emit('pause') | ||
this.bus.emit('pause', remaining()) | ||
return this | ||
@@ -152,0 +157,0 @@ } |
{ | ||
"name": "nanotween", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Tiny library for tweening", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# NanoTween | ||
1.5 KB is quite enough for comfortable tweening | ||
1.5 KB is quite enough for comfortable tweening | ||
![image](https://user-images.githubusercontent.com/4208480/34684747-27532bc4-f4b7-11e7-9387-bc4e87ad0eab.png) | ||
@@ -5,0 +5,0 @@ |
29079
1021