@figliolia/react-hooks
Version:
A small collection of simple React Hooks you're probably rewriting on a regular basis
31 lines (30 loc) • 673 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Timeout = void 0;
class Timeout {
constructor() {
this.IDs = new Set();
}
execute(callback, delay = 0) {
const ID = setTimeout(() => {
callback();
}, delay);
this.IDs.add(ID);
return () => {
this.clear(ID);
};
}
abortAll() {
for (const ID of this.IDs) {
clearTimeout(ID);
}
this.IDs.clear();
}
clear(ID) {
if (ID && this.IDs.has(ID)) {
clearTimeout(ID);
this.IDs.delete(ID);
}
}
}
exports.Timeout = Timeout;