pithos
Version:
Advanced JavaScript/TypeScript superset providing performance, gestures, animations, and DOM utilities
27 lines • 601 B
JavaScript
export class Debouncer {
constructor(delay, callback) {
this.delay = delay;
this.callback = callback;
this.timeout = null;
}
schedule() {
this.cancel();
this.timeout = window.setTimeout(() => {
this.callback();
this.timeout = null;
}, this.delay);
}
trigger() {
this.schedule();
}
cancel() {
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = null;
}
}
destroy() {
this.cancel();
}
}
//# sourceMappingURL=debouncer.js.map