export class TimerUtils {

    // private static debounceTimers: DebounceTimer[];

    // private static addDebounceTimer(key: string, debounceTime: number, callback: Function) {
    //     if (!this.debounceTimers) {
    //         this.debounceTimers = [];
    //     }
    //     let timerProfile = this.debounceTimers.find(t => t.key == key);
    //     if (timerProfile) {
    //         clearTimeout(timerProfile.timer);
    //     } else {
    //         timerProfile = new DebounceTimer(){

    //         }
    //     }
    // }

}

export class DebounceTimer {

    constructor(
        debounceTime: number,
        callback: Function
    ) {
        //this.key = key
        this.debounceTime = debounceTime;
        this.callback = callback;
        //this.resetTimer();
    }

    debounceTime: number;
    timer: any;
    callback: Function;
    resetTimer() {
        if (this.timer) {
            clearTimeout(this.timer);
        }
        this.timer = setTimeout(() => {
            this.callback();
            this.timer = null;
        }, this.debounceTime);
    }
    clearOut() {
        if (this.timer) {
            clearTimeout(this.timer);
        }
    }
}