All files / app/codeCharta/util debounce.ts

100% Statements 6/6
100% Branches 1/1
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 1132x   110x 29x 29x 10x 10x        
export function debounce<F extends (...arguments_: Parameters<F>) => ReturnType<F>>(this: unknown, function_: F, waitInMS = 0) {
    let timer
    return (...arguments_: Parameters<F>) => {
        clearTimeout(timer)
        timer = setTimeout(() => {
            function_.apply(this, arguments_)
            timer = null
        }, waitInMS)
    }
}