uno-js
Version:
JS/TS common used functions, zero dependencies
18 lines (17 loc) • 511 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.debounce = debounce;
function debounce(func, waitMilliseconds = 500) {
let timeoutId;
return ((t, ...args) => {
const context = t;
const doLater = () => {
timeoutId = undefined;
func.apply(context, args);
};
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
}
timeoutId = window.setTimeout(doLater, waitMilliseconds);
});
}