Files
ionic-framework/src/util/debouncer.ts
2016-06-16 12:34:46 -05:00

26 lines
442 B
TypeScript

export class Debouncer {
private timer: number = null;
callback: Function;
constructor(public wait: number) { }
debounce(callback: Function) {
this.callback = callback;
this.schedule();
}
schedule() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
if (this.wait <= 0) {
this.callback();
} else {
this.timer = setTimeout(this.callback, this.wait);
}
}
}