"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = debounce;
function debounce(func, wait, immediate) {
var timeout = void 0;
var args = void 0;
var context = void 0;
var timestamp = void 0;
var result = void 0;
var later = function later() {
var last = +new Date() - timestamp;
if (last < wait && last >= 0) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
Eif (!immediate) {
result = func.apply(context, args);
Eif (!timeout) {
context = args = null;
}
}
}
};
return function debounced() {
context = this;
args = arguments;
timestamp = +new Date();
var callNow = immediate && !timeout;
if (!timeout) {
timeout = setTimeout(later, wait);
}
Iif (callNow) {
result = func.apply(context, args);
context = args = null;
}
return result;
};
}
|