json-joy
Version:
Collection of libraries for building collaborative editing apps.
25 lines (24 loc) • 564 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.throttle = void 0;
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];
};
exports.throttle = throttle;
;