UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

21 lines (20 loc) 438 B
export const throttle = (fn, ms = 25) => { let timer; let lastArgs; const stop = () => { if (timer) { clearTimeout(timer); timer = 0; } }; const out = ((...args) => { lastArgs = args; if (timer) return; timer = setTimeout(() => { timer = 0; fn.apply(null, lastArgs); }, ms); }); return [out, stop]; };