Comparing version 0.1.2 to 0.2.0
@@ -1,1 +0,1 @@ | ||
var version = "0.1.2"; export * from "../index"; export {version}; | ||
var version = "0.2.0"; export * from "../index"; export {version}; |
@@ -11,4 +11,2 @@ (function (global, factory) { | ||
var taskTail; | ||
var taskId = 0; | ||
var taskById = {}; | ||
var setFrame = typeof window !== "undefined" | ||
@@ -23,3 +21,5 @@ && (window.requestAnimationFrame | ||
function Timer() { | ||
this.id = ++taskId; | ||
this._call = | ||
this._time = | ||
this._next = null; | ||
} | ||
@@ -31,17 +31,15 @@ | ||
time = (time == null ? Date.now() : +time) + (delay == null ? 0 : +delay); | ||
var i = this.id, t = taskById[i]; | ||
if (t) { | ||
t.callback = callback, t.time = time; | ||
} else { | ||
t = {next: null, callback: callback, time: time}; | ||
if (taskTail) taskTail.next = t; else taskHead = t; | ||
taskById[i] = taskTail = t; | ||
if (!this._call) { | ||
if (taskTail) taskTail._next = this; | ||
else taskHead = this; | ||
taskTail = this; | ||
} | ||
this._call = callback; | ||
this._time = time; | ||
sleep(); | ||
}, | ||
stop: function() { | ||
var i = this.id, t = taskById[i]; | ||
if (t) { | ||
t.callback = null, t.time = Infinity; | ||
delete taskById[i]; | ||
if (this._call) { | ||
this._call = null; | ||
this._time = Infinity; | ||
sleep(); | ||
@@ -67,11 +65,22 @@ } | ||
++frame; // Pretend we’ve set an alarm, if we haven’t already. | ||
try { | ||
var t = taskHead, c; | ||
while (t) { | ||
if (now >= t.time) c = t.callback, c(now - t.time, now); | ||
t = t.next; | ||
var t = taskHead; | ||
while (t) { | ||
if (now >= t._time) t._call.call(null, now - t._time, now); | ||
t = t._next; | ||
} | ||
--frame; | ||
} | ||
function timerSweep() { | ||
var t0, t1 = taskHead, time = Infinity; | ||
while (t1) { | ||
if (t1._call) { | ||
if (time > t1._time) time = t1._time; | ||
t1 = (t0 = t1)._next; | ||
} else { | ||
t1 = t0 ? t0._next = t1._next : taskHead = t1._next; | ||
} | ||
} finally { | ||
--frame; | ||
} | ||
taskTail = t0; | ||
return time; | ||
} | ||
@@ -84,13 +93,4 @@ | ||
} finally { | ||
var t0, t1 = taskHead, time = Infinity; | ||
while (t1) { | ||
if (t1.callback) { | ||
if (time > t1.time) time = t1.time; | ||
t1 = (t0 = t1).next; | ||
} else { | ||
t1 = t0 ? t0.next = t1.next : taskHead = t1.next; | ||
} | ||
} | ||
taskTail = t0; | ||
sleep(time); | ||
frame = 0; | ||
sleep(timerSweep()); | ||
} | ||
@@ -107,3 +107,3 @@ } | ||
var version = "0.1.2"; | ||
var version = "0.2.0"; | ||
@@ -110,0 +110,0 @@ exports.version = version; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.d3_timer={})}(this,function(t){"use strict";function e(){this.id=++m}function n(t,n,i){var o=new e;return o.restart(t,n,i),o}function i(t,n,i){var o=new e;return o.restart(function(e,n){o.stop(),t(e,n)},n,i),o}function o(t){t=null==t?Date.now():+t,++f;try{for(var e,n=u;n;)t>=n.time&&(e=n.callback)(t-n.time,t),n=n.next}finally{--f}}function r(){f=l=0;try{o()}finally{for(var t,e=u,n=1/0;e;)e.callback?(n>e.time&&(n=e.time),e=(t=e).next):e=t?t.next=e.next:u=e.next;c=t,a(n)}}function a(t){if(!f){l&&(l=clearTimeout(l));var e=t-Date.now();e>24?1/0>t&&(l=setTimeout(r,e)):(f=1,d(r))}}var u,c,f=0,l=0,m=0,s={},d="undefined"!=typeof window&&(window.requestAnimationFrame||window.msRequestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.oRequestAnimationFrame)||function(t){return setTimeout(t,17)};e.prototype=n.prototype={restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?Date.now():+n)+(null==e?0:+e);var i=this.id,o=s[i];o?(o.callback=t,o.time=n):(o={next:null,callback:t,time:n},c?c.next=o:u=o,s[i]=c=o),a()},stop:function(){var t=this.id,e=s[t];e&&(e.callback=null,e.time=1/0,delete s[t],a())}};var w="0.1.2";t.version=w,t.timer=n,t.timerOnce=i,t.timerFlush=o}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.d3_timer={})}(this,function(t){"use strict";function n(){this._call=this._time=this._next=null}function e(t,e,i){var o=new n;return o.restart(t,e,i),o}function i(t,e,i){var o=new n;return o.restart(function(n,e){o.stop(),t(n,e)},e,i),o}function o(t){t=null==t?Date.now():+t,++f;for(var n=l;n;)t>=n._time&&n._call.call(null,t-n._time,t),n=n._next;--f}function r(){for(var t,n=l,e=1/0;n;)n._call?(e>n._time&&(e=n._time),n=(t=n)._next):n=t?t._next=n._next:l=n._next;return s=t,e}function u(){f=c=0;try{o()}finally{f=0,a(r())}}function a(t){if(!f){c&&(c=clearTimeout(c));var n=t-Date.now();n>24?1/0>t&&(c=setTimeout(u,n)):(f=1,m(u))}}var l,s,f=0,c=0,m="undefined"!=typeof window&&(window.requestAnimationFrame||window.msRequestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.oRequestAnimationFrame)||function(t){return setTimeout(t,17)};n.prototype=e.prototype={restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?Date.now():+e)+(null==n?0:+n),this._call||(s?s._next=this:l=this,s=this),this._call=t,this._time=e,a()},stop:function(){this._call&&(this._call=null,this._time=1/0,a())}};var _="0.2.0";t.version=_,t.timer=e,t.timerOnce=i,t.timerFlush=o}); |
{ | ||
"name": "d3-timer", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "An efficient queue capable of managing thousands of concurrent animations.", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"prepublish": "npm run test && uglifyjs build/d3-timer.js -c -m -o build/d3-timer.min.js && rm -f build/d3-timer.zip && zip -j build/d3-timer.zip -- LICENSE README.md build/d3-timer.js build/d3-timer.min.js", | ||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git tag -am \"Release $VERSION.\" v${VERSION} && git push --tags && cp build/d3-timer.js ../d3.github.com/d3-timer.v0.1.js && cp build/d3-timer.min.js ../d3.github.com/d3-timer.v0.1.min.js && cd ../d3.github.com && git add d3-timer.v0.1.js d3-timer.v0.1.min.js && git commit -m \"d3-timer ${VERSION}\" && git push" | ||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git tag -am \"Release $VERSION.\" v${VERSION} && git push --tags && cp build/d3-timer.js ../d3.github.com/d3-timer.v0.2.js && cp build/d3-timer.min.js ../d3.github.com/d3-timer.v0.2.min.js && cd ../d3.github.com && git add d3-timer.v0.2.js d3-timer.v0.2.min.js && git commit -m \"d3-timer ${VERSION}\" && git push" | ||
}, | ||
@@ -33,0 +33,0 @@ "devDependencies": { |
@@ -10,3 +10,3 @@ # d3-timer | ||
```html | ||
<script src="https://d3js.org/d3-timer.v0.1.min.js"></script> | ||
<script src="https://d3js.org/d3-timer.v0.2.min.js"></script> | ||
``` | ||
@@ -59,3 +59,3 @@ | ||
Restart a timer with the specified *callback* and optional *delay* and *time*. This is equivalent to stopping this timer and creating a new timer with the specified arguments, although this timer retains the original [id](#timer_id) and invocation priority. | ||
Restart a timer with the specified *callback* and optional *delay* and *time*. This is equivalent to stopping this timer and creating a new timer with the specified arguments, although this timer retains the original invocation priority. | ||
@@ -66,6 +66,2 @@ <a name="timer_stop" href="#timer_stop">#</a> <i>timer</i>.<b>stop</b>() | ||
<a name="timer_id" href="#timer_id">#</a> <i>timer</i>.<b>id</b> | ||
An opaque, unique identifier for this timer. | ||
<a name="timerOnce" href="#timerOnce">#</a> d3.<b>timerOnce</b>(<i>callback</i>[, <i>delay</i>[, <i>time</i>]]) | ||
@@ -72,0 +68,0 @@ |
var frame = 0, // is an animation frame pending? | ||
timeout = 0, // is a timeout pending? | ||
taskHead, | ||
taskTail, | ||
taskId = 0, | ||
taskById = {}; | ||
taskTail; | ||
@@ -17,3 +15,5 @@ var setFrame = typeof window !== "undefined" | ||
function Timer() { | ||
this.id = ++taskId; | ||
this._call = | ||
this._time = | ||
this._next = null; | ||
} | ||
@@ -25,17 +25,15 @@ | ||
time = (time == null ? Date.now() : +time) + (delay == null ? 0 : +delay); | ||
var i = this.id, t = taskById[i]; | ||
if (t) { | ||
t.callback = callback, t.time = time; | ||
} else { | ||
t = {next: null, callback: callback, time: time}; | ||
if (taskTail) taskTail.next = t; else taskHead = t; | ||
taskById[i] = taskTail = t; | ||
if (!this._call) { | ||
if (taskTail) taskTail._next = this; | ||
else taskHead = this; | ||
taskTail = this; | ||
} | ||
this._call = callback; | ||
this._time = time; | ||
sleep(); | ||
}, | ||
stop: function() { | ||
var i = this.id, t = taskById[i]; | ||
if (t) { | ||
t.callback = null, t.time = Infinity; | ||
delete taskById[i]; | ||
if (this._call) { | ||
this._call = null; | ||
this._time = Infinity; | ||
sleep(); | ||
@@ -61,11 +59,22 @@ } | ||
++frame; // Pretend we’ve set an alarm, if we haven’t already. | ||
try { | ||
var t = taskHead, c; | ||
while (t) { | ||
if (now >= t.time) c = t.callback, c(now - t.time, now); | ||
t = t.next; | ||
var t = taskHead; | ||
while (t) { | ||
if (now >= t._time) t._call.call(null, now - t._time, now); | ||
t = t._next; | ||
} | ||
--frame; | ||
} | ||
function timerSweep() { | ||
var t0, t1 = taskHead, time = Infinity; | ||
while (t1) { | ||
if (t1._call) { | ||
if (time > t1._time) time = t1._time; | ||
t1 = (t0 = t1)._next; | ||
} else { | ||
t1 = t0 ? t0._next = t1._next : taskHead = t1._next; | ||
} | ||
} finally { | ||
--frame; | ||
} | ||
taskTail = t0; | ||
return time; | ||
} | ||
@@ -78,13 +87,4 @@ | ||
} finally { | ||
var t0, t1 = taskHead, time = Infinity; | ||
while (t1) { | ||
if (t1.callback) { | ||
if (time > t1.time) time = t1.time; | ||
t1 = (t0 = t1).next; | ||
} else { | ||
t1 = t0 ? t0.next = t1.next : taskHead = t1.next; | ||
} | ||
} | ||
taskTail = t0; | ||
sleep(time); | ||
frame = 0; | ||
sleep(timerSweep()); | ||
} | ||
@@ -91,0 +91,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14664
187
73