Comparing version 0.1.1 to 0.1.2
@@ -1,1 +0,1 @@ | ||
var version = "0.1.1"; export * from "../index"; export {version}; | ||
var version = "0.1.2"; export * from "../index"; export {version}; |
@@ -21,5 +21,4 @@ (function (global, factory) { | ||
function Timer(callback, delay, time) { | ||
function Timer() { | ||
this.id = ++taskId; | ||
this.restart(callback, delay, time); | ||
} | ||
@@ -52,7 +51,15 @@ | ||
function timer(callback, delay, time) { | ||
return new Timer(callback, delay, time); | ||
var t = new Timer; | ||
t.restart(callback, delay, time); | ||
return t; | ||
} | ||
function timerFlush(time) { | ||
time = time == null ? Date.now() : +time; | ||
function timerOnce(callback, delay, time) { | ||
var t = new Timer; | ||
t.restart(function(elapsed, now) { t.stop(); callback(elapsed, now); }, delay, time); | ||
return t; | ||
} | ||
function timerFlush(now) { | ||
now = now == null ? Date.now() : +now; | ||
++frame; // Pretend we’ve set an alarm, if we haven’t already. | ||
@@ -62,3 +69,3 @@ try { | ||
while (t) { | ||
if (time >= t.time) c = t.callback, c(time - t.time, time); | ||
if (now >= t.time) c = t.callback, c(now - t.time, now); | ||
t = t.next; | ||
@@ -98,8 +105,9 @@ } | ||
var version = "0.1.1"; | ||
var version = "0.1.2"; | ||
exports.version = version; | ||
exports.timer = timer; | ||
exports.timerOnce = timerOnce; | ||
exports.timerFlush = timerFlush; | ||
})); |
@@ -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(t,e,n){this.id=++c,this.restart(t,e,n)}function n(t,n,i){return new e(t,n,i)}function i(t){t=null==t?Date.now():+t,++l;try{for(var e,n=a;n;)t>=n.time&&(e=n.callback)(t-n.time,t),n=n.next}finally{--l}}function o(){l=f=0;try{i()}finally{for(var t,e=a,n=1/0;e;)e.callback?(n>e.time&&(n=e.time),e=(t=e).next):e=t?t.next=e.next:a=e.next;u=t,r(n)}}function r(t){if(!l){f&&(f=clearTimeout(f));var e=t-Date.now();e>24?1/0>t&&(f=setTimeout(o,e)):(l=1,s(o))}}var a,u,l=0,f=0,c=0,m={},s="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=m[i];o?(o.callback=t,o.time=n):(o={next:null,callback:t,time:n},u?u.next=o:a=o,m[i]=u=o),r()},stop:function(){var t=this.id,e=m[t];e&&(e.callback=null,e.time=1/0,delete m[t],r())}};var d="0.1.1";t.version=d,t.timer=n,t.timerFlush=i}); | ||
!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}); |
export { | ||
timer, | ||
timerOnce, | ||
timerFlush | ||
} from "./src/timer"; |
{ | ||
"name": "d3-timer", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "An efficient queue capable of managing thousands of concurrent animations.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -21,7 +21,7 @@ # d3-timer | ||
The *callback* is passed two arguments when it is invoked: the elapsed time since the timer became active, and the current time. The latter is useful for precise scheduling of secondary timers. For example: | ||
The *callback* is passed two arguments when it is invoked: the *elapsed* time since the timer became active, and the current time, *now*. The latter is useful for precise scheduling of secondary timers. For example: | ||
```js | ||
var t = d3.timer(function(elapsed, time) { | ||
console.log(elapsed, time); | ||
var t = d3.timer(function(elapsed, now) { | ||
console.log(elapsed, now); | ||
if (elapsed > 200) t.stop(); | ||
@@ -69,2 +69,6 @@ }, 150); | ||
<a name="timerOnce" href="#timerOnce">#</a> d3.<b>timerOnce</b>(<i>callback</i>[, <i>delay</i>[, <i>time</i>]]) | ||
Like [timer](#timer), except the timer automatically [stops](#timer_stop) on its first callback. | ||
<a name="timerFlush" href="#timerFlush">#</a> d3.<b>timerFlush</b>([<i>time</i>]) | ||
@@ -71,0 +75,0 @@ |
@@ -16,5 +16,4 @@ var frame = 0, // is an animation frame pending? | ||
function Timer(callback, delay, time) { | ||
function Timer() { | ||
this.id = ++taskId; | ||
this.restart(callback, delay, time); | ||
} | ||
@@ -47,7 +46,15 @@ | ||
export function timer(callback, delay, time) { | ||
return new Timer(callback, delay, time); | ||
var t = new Timer; | ||
t.restart(callback, delay, time); | ||
return t; | ||
} | ||
export function timerFlush(time) { | ||
time = time == null ? Date.now() : +time; | ||
export function timerOnce(callback, delay, time) { | ||
var t = new Timer; | ||
t.restart(function(elapsed, now) { t.stop(); callback(elapsed, now); }, delay, time); | ||
return t; | ||
} | ||
export function timerFlush(now) { | ||
now = now == null ? Date.now() : +now; | ||
++frame; // Pretend we’ve set an alarm, if we haven’t already. | ||
@@ -57,3 +64,3 @@ try { | ||
while (t) { | ||
if (time >= t.time) c = t.callback, c(time - t.time, time); | ||
if (now >= t.time) c = t.callback, c(now - t.time, now); | ||
t = t.next; | ||
@@ -60,0 +67,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
15073
189
77