simple-lazy-debounce
Version:
Lazy delay support debounce function
24 lines (23 loc) • 533 B
JavaScript
const m = (l, {
defaultDelay: o = 300,
maxDelay: n = 500,
latencyIncrement: r = 100
} = {}) => {
const c = [
["defaultDelay", o],
["maxDelay", n],
["latencyIncrement", r]
];
for (const [e, s] of c)
if (!Number.isInteger(s) || s < 0)
throw new Error(`Invalid option: ${e}`);
let t = o, i = 0, a;
return (...e) => {
t = Date.now() - i > t ? Math.min(t + r, n) : o, clearTimeout(a), a = setTimeout(() => {
l(...e), i = Date.now();
}, t);
};
};
export {
m as SimpleLazyDebounce
};