@ohu-mobile/core
Version:
28 lines (27 loc) • 675 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = debounce;
function debounce(func) {
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 166;
var timeout;
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);
}
timeout = setTimeout(function () {
func.apply(_this, args);
}, wait);
}
debounced.clear = function () {
if (timeout) {
clearTimeout(timeout);
}
};
return debounced;
}