UNPKG

tweak-tools

Version:

Tweak your React projects until awesomeness

18 lines (17 loc) 537 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.debounce = void 0; const debounce = (callback, wait, immediate = false) => { let timeout = 0; return function () { const args = arguments; const callNow = immediate && !timeout; // @ts-expect-error const next = () => callback.apply(this, args); window.clearTimeout(timeout); timeout = window.setTimeout(next, wait); if (callNow) next(); }; }; exports.debounce = debounce;