@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
23 lines • 691 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.debounce = debounce;
function debounce(func, waitMilliseconds, immediate = false) {
let timeoutId;
return (...args) => {
const doLater = () => {
timeoutId = undefined;
if (!immediate) {
func(...args);
}
};
const shouldCallNow = immediate && timeoutId === undefined;
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(doLater, waitMilliseconds);
if (shouldCallNow) {
func(...args);
}
};
}
//# sourceMappingURL=debounce.js.map