@byojs/scheduler
Advanced tools
Comparing version 0.0.9 to 0.9.0
{ | ||
"name": "@byojs/scheduler", | ||
"description": "Throttle/debounce scheduler", | ||
"version": "0.0.9", | ||
"version": "0.9.0", | ||
"exports": { | ||
@@ -30,6 +30,12 @@ "./": "./dist/scheduler.mjs" | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"debounce", | ||
"throttle", | ||
"scheduling", | ||
"task", | ||
"async" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/byojs/scheduler/issues", | ||
"email": "--TODO--" | ||
"email": "getify@gmail.com" | ||
}, | ||
@@ -36,0 +42,0 @@ "homepage": "https://github.com/byojs/scheduler", |
@@ -6,4 +6,4 @@ export default Scheduler; | ||
function Scheduler(debounceMin,throttleMax = Infinity,leading = false) { | ||
throttleMax = Math.max(debounceMin,throttleMax); | ||
function Scheduler(initialDelay,maxDelay = Infinity,leading = false) { | ||
maxDelay = Math.max(initialDelay,maxDelay); | ||
var entries = new WeakMap(); | ||
@@ -43,7 +43,7 @@ | ||
// NO room left to debounce while still under the throttle-max? | ||
!((now - entry.last) <= throttleMax) | ||
!((now - entry.last) <= maxDelay) | ||
) { | ||
clearTimer(entry); | ||
fn(); | ||
entry.timer = setTimeout(clearTimer,debounceMin,entry); | ||
entry.timer = setTimeout(clearTimer,initialDelay,entry); | ||
} | ||
@@ -60,3 +60,3 @@ else { | ||
// room left to debounce while still under the throttle-max? | ||
(now - entry.last) < throttleMax | ||
(now - entry.last) < maxDelay | ||
) { | ||
@@ -77,3 +77,3 @@ setTimer(fn,entry,now); | ||
clearTimer(entry); | ||
var time = Math.min(debounceMin,Math.max(0,(entry.last + throttleMax) - now)); | ||
var time = Math.min(initialDelay,Math.max(0,(entry.last + maxDelay) - now)); | ||
entry.timer = setTimeout(run,time,fn,entry); | ||
@@ -80,0 +80,0 @@ } |
Sorry, the diff of this file is not supported yet
24436