RevelaOS/node_modules/just-debounce-it/index.js
2023-10-15 23:53:41 +01:00

24 lines
504 B
JavaScript

module.exports = debounce;
function debounce(fn, wait, callFirst) {
var timeout;
return function() {
if (!wait) {
return fn.apply(this, arguments);
}
var context = this;
var args = arguments;
var callNow = callFirst && !timeout;
clearTimeout(timeout);
timeout = setTimeout(function() {
timeout = null;
if (!callNow) {
return fn.apply(context, args);
}
}, wait);
if (callNow) {
return fn.apply(this, arguments);
}
};
}