wix-style-react
Version:
26 lines (22 loc) • 731 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.debounce = void 0;
/** Lodash debounce doesn't play nicely with jest fake timers,
* so we provide a simplified debouncing function for unit test. */
var debounce = function debounce(callback) {
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
var timeoutId;
return function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
clearTimeout(timeoutId);
timeoutId = setTimeout(function () {
timeoutId = null;
callback.apply(void 0, args);
}, delay);
};
};
exports.debounce = debounce;