UNPKG

froebel

Version:
33 lines (30 loc) 898 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.cancel = void 0; const cancel = Symbol("debounce.cancel"); /** * Creates a debounced function that delays invoking `fun` until `ms` milliseconds * have passed since the last invocation of the debounced function. * * `fun` is invoked with the last arguments passed to the debounced function. * * Calling `[debounce.cancel]()` on the debounced function will cancel the currently * scheduled invocation. */ exports.cancel = cancel; const debounce = Object.assign((fun, ms) => { let toId; return Object.assign((...args) => { clearTimeout(toId); toId = setTimeout(() => fun(...args), ms); }, { [cancel]: () => clearTimeout(toId) }); }, { cancel }); var _default = debounce; exports.default = _default; module.exports = Object.assign(exports.default || {}, exports);