zarm-web
Version:
基于 React 的桌面端UI库
39 lines (32 loc) • 767 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = debounce;
function debounce(func, wait, immediate) {
var timeout;
var result;
return function debounced() {
var _this = this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (timeout) {
clearTimeout(timeout);
}
if (immediate) {
var callNow = !timeout;
timeout = setTimeout(function () {
timeout = null;
}, wait);
if (callNow) {
result = func.apply(this, args);
}
} else {
timeout = setTimeout(function () {
func.apply(_this, args);
}, wait);
}
return result;
};
}