UNPKG

775 BJavaScriptView Raw
1var TimeoutDebouncer = (function () {
2 function TimeoutDebouncer(wait) {
3 this.wait = wait;
4 this.timer = null;
5 }
6 TimeoutDebouncer.prototype.debounce = function (callback) {
7 this.callback = callback;
8 this.schedule();
9 };
10 TimeoutDebouncer.prototype.schedule = function () {
11 this.cancel();
12 if (this.wait <= 0) {
13 this.callback();
14 }
15 else {
16 this.timer = setTimeout(this.callback, this.wait);
17 }
18 };
19 TimeoutDebouncer.prototype.cancel = function () {
20 if (this.timer) {
21 clearTimeout(this.timer);
22 this.timer = null;
23 }
24 };
25 return TimeoutDebouncer;
26}());
27export { TimeoutDebouncer };
28//# sourceMappingURL=debouncer.js.map
\No newline at end of file