"use strict";
exports.__esModule = true;
exports["default"] = debounce;
function debounce(func, wait, immediate) {
var timeout = undefined;
var args = undefined;
var context = undefined;
var timestamp = undefined;
var result = undefined;
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;
};
}
module.exports = exports["default"];
|