ensure-debounce.ts

16 lines | 439 B Blame History Raw Download
export function debounceManager(debounceTime: number): { ensureDebounce: (fn: Function) => void } {

    var curHandle: number | null = null;

    return {
        ensureDebounce: (fn: Function) => {
            if (curHandle != null) {
                clearInterval(curHandle);
                curHandle = null;
            }
            curHandle = setTimeout(() => {
                fn();
            }, debounceTime);
        }
    }
}