Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3-timer

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-timer - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

77

build/timer.js

@@ -1,10 +0,1 @@

if (typeof requestAnimationFrame === "undefined") {
requestAnimationFrame = typeof window !== "undefined"
&& (window.msRequestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.oRequestAnimationFrame)
|| function(callback) { return setTimeout(callback, 17); };
}
(function (global, factory) {

@@ -16,30 +7,18 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

var queueHead,
queueTail,
active, // the currently-executing timer
frame, // is an animation frame pending?
timeout, // is a timeout pending?
timeoutTime = Infinity; // the time the timeout will fire
var queueHead;
var queueTail;
var active;
var frame;
var timeout;
var timeoutTime = Infinity;
// the time the timeout will fire
function wake() {
frame = timeout = 0, timeoutTime = Infinity;
wakeAt(timerFlush());
}
var setFrame = typeof window !== "undefined"
&& (window.requestAnimationFrame
|| window.msRequestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.oRequestAnimationFrame)
|| function(callback) { return setTimeout(callback, 17); };
function wakeAt(time) {
if (frame) return; // Fastest wake already set.
var delay = time - Date.now();
if (delay > 24) {
if (timeoutTime > time) { // Note: false if time is infinite.
if (timeout) clearTimeout(timeout);
timeout = setTimeout(wake, delay);
timeoutTime = time;
}
} else {
if (timeout) timeout = clearTimeout(timeout), timeoutTime = Infinity;
frame = requestAnimationFrame(wake);
}
}
// The timer will continue to fire until callback returns true.

@@ -57,6 +36,3 @@ function timer(callback, delay, time) {

wakeAt(time);
}
// Replace the current timer. Only allowed within a timer callback.
}// Replace the current timer. Only allowed within a timer callback.
function timerReplace(callback, delay, time) {

@@ -67,6 +43,3 @@ if (time == null) time = Date.now(); else time = +time;

active.time = time;
}
// Execute all eligible timers,
}// Execute all eligible timers,
// then flush completed timers to avoid concurrent queue modification.

@@ -102,4 +75,22 @@ // Returns the time of the earliest active timer.

return time;
}function wake() {
frame = timeout = 0, timeoutTime = Infinity;
wakeAt(timerFlush());
}
function wakeAt(time) {
if (frame) return; // Fastest wake already set.
var delay = time - Date.now();
if (delay > 24) {
if (timeoutTime > time) { // Note: false if time is infinite.
if (timeout) clearTimeout(timeout);
timeout = setTimeout(wake, delay);
timeoutTime = time;
}
} else {
if (timeout) timeout = clearTimeout(timeout), timeoutTime = Infinity;
frame = setFrame(wake);
}
}
exports.timer = timer;

@@ -106,0 +97,0 @@ exports.timerReplace = timerReplace;

@@ -1,1 +0,1 @@

"undefined"==typeof requestAnimationFrame&&(requestAnimationFrame="undefined"!=typeof window&&(window.msRequestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.oRequestAnimationFrame)||function(e){return setTimeout(e,17)}),function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.timer={})}(this,function(e){"use strict";function n(){f=l=0,c=1/0,t(u())}function t(e){if(!f){var t=e-Date.now();t>24?c>e&&(l&&clearTimeout(l),l=setTimeout(n,t),c=e):(l&&(l=clearTimeout(l),c=1/0),f=requestAnimationFrame(n))}}function i(e,n,i){i=null==i?Date.now():+i,null!=n&&(i+=+n);var o={callback:e,time:i,flush:!1,next:null};m?m.next=o:a=o,m=o,t(i)}function o(e,n,t){t=null==t?Date.now():+t,null!=n&&(t+=+n),r.callback=e,r.time=t}function u(e){e=null==e?Date.now():+e;var n=r;for(r=a;r;)e>=r.time&&(r.flush=r.callback(e-r.time,e)),r=r.next;r=n,e=1/0;for(var t,i=a;i;)i.flush?i=t?t.next=i.next:a=i.next:(i.time<e&&(e=i.time),i=(t=i).next);return m=t,e}var a,m,r,f,l,c=1/0;e.timer=i,e.timerReplace=o,e.timerFlush=u});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.timer={})}(this,function(e){"use strict";function n(e,n,t){t=null==t?Date.now():+t,null!=n&&(t+=+n);var i={callback:e,time:t,flush:!1,next:null};m?m.next=i:a=i,m=i,u(t)}function t(e,n,t){t=null==t?Date.now():+t,null!=n&&(t+=+n),r.callback=e,r.time=t}function i(e){e=null==e?Date.now():+e;var n=r;for(r=a;r;)e>=r.time&&(r.flush=r.callback(e-r.time,e)),r=r.next;r=n,e=1/0;for(var t,i=a;i;)i.flush?i=t?t.next=i.next:a=i.next:(i.time<e&&(e=i.time),i=(t=i).next);return m=t,e}function o(){l=f=0,c=1/0,u(i())}function u(e){if(!l){var n=e-Date.now();n>24?c>e&&(f&&clearTimeout(f),f=setTimeout(o,n),c=e):(f&&(f=clearTimeout(f),c=1/0),l=s(o))}}var a,m,r,l,f,c=1/0,s="undefined"!=typeof window&&(window.requestAnimationFrame||window.msRequestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.oRequestAnimationFrame)||function(e){return setTimeout(e,17)};e.timer=n,e.timerReplace=t,e.timerFlush=i});
{
"name": "d3-timer",
"version": "0.0.3",
"version": "0.0.4",
"description": "An efficient queue capable of managing thousands of concurrent animations.",

@@ -27,3 +27,3 @@ "keywords": [

"scripts": {
"pretest": "mkdir -p build && d3-bundler --polyfill-raf --format=umd --name=timer -- index.js > build/timer.js",
"pretest": "mkdir -p build && d3-bundler --format=umd --name=timer -- index.js > build/timer.js",
"test": "faucet `find test -name '*-test.js'`",

@@ -33,7 +33,7 @@ "prepublish": "npm run test && uglifyjs build/timer.js -c -m -o build/timer.min.js && rm -f build/timer.zip && zip -j build/timer.zip -- LICENSE README.md build/timer.js build/timer.min.js"

"devDependencies": {
"d3-bundler": "~0.2.6",
"d3-bundler": "~0.3.0",
"faucet": "0.0",
"tape": "4",
"uglifyjs": "2"
"uglify-js": "2"
}
}

@@ -5,12 +5,8 @@ # d3-timer

Changes from D3 3.x:
## Installing
* Timer callbacks are now passed the current time as a second argument, in addition to the elapsed time; this is useful for precise scheduling of secondary timers.
If you use NPM, `npm install d3-timer`. Otherwise, download the [latest release](https://github.com/d3/d3-timer/releases/latest).
* A new [timerReplace](#timerReplace) method has been added to replace the current timer within a timer callback.
## API Reference
* The timer.flush method has been renamed [timerFlush](#timerFlush). This method now accepts an optional *time* argument representing the current time, and returns the time of the earliest next timer. Calling this method within a timer callback no longer causes a crash.
* Calling [timer](#timer) within a timer callback no longer makes a duplicate requestAnimationFrame. Calling this method with a delay greater than 24ms when no earlier timers are active guarantees a setTimeout rather than a requestAnimationFrame.
<a name="timer" href="#timer">#</a> <b>timer</b>(<i>callback</i>[, <i>delay</i>[, <i>time</i>]])

@@ -64,1 +60,11 @@

Replace the current timer’s *callback*, *delay* and *time*. This method can only be called within a timer callback, and is equivalent to [timer](#timer), except that it replaces the current timer rather than scheduling a new timer.
## Changes from D3 3.x:
* Timer callbacks are now passed the current time as a second argument, in addition to the elapsed time; this is useful for precise scheduling of secondary timers.
* A new [timerReplace](#timerReplace) method has been added to replace the current timer within a timer callback.
* The timer.flush method has been renamed [timerFlush](#timerFlush). This method now accepts an optional *time* argument representing the current time, and returns the time of the earliest next timer. Calling this method within a timer callback no longer causes a crash.
* Calling [timer](#timer) within a timer callback no longer makes a duplicate requestAnimationFrame. Calling this method with a delay greater than 24ms when no earlier timers are active guarantees a setTimeout rather than a requestAnimationFrame.

@@ -8,2 +8,10 @@ var queueHead,

var setFrame = typeof window !== "undefined"
&& (window.requestAnimationFrame
|| window.msRequestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.oRequestAnimationFrame)
|| function(callback) { return setTimeout(callback, 17); };
// The timer will continue to fire until callback returns true.

@@ -80,4 +88,4 @@ export function timer(callback, delay, time) {

if (timeout) timeout = clearTimeout(timeout), timeoutTime = Infinity;
frame = requestAnimationFrame(wake);
frame = setFrame(wake);
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc