@three11/debounce
Version:
Debounce multiple function executions
39 lines (34 loc) • 1.33 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.debounce = {}));
})(this, (function (exports) { 'use strict';
var debounce = function (fn, delay, isImmediate) {
if (delay === void 0) { delay = 15; }
if (isImmediate === void 0) { isImmediate = false; }
var timeout;
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var context = this;
if (isImmediate && !timeout) {
fn.apply(context, args);
}
if (typeof timeout === 'number') {
clearTimeout(timeout);
}
timeout = setTimeout(function () {
timeout = null;
if (!isImmediate) {
fn.apply(context, args);
}
}, delay);
};
};
exports.debounce = debounce;
exports.default = debounce;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=debounce.js.map