Files
remark42/frontend/app/utils/debounce.ts
T
Misha VyrtsevandUmputun 9fbdff106d Update deps 2019 09 (#439)
* update minor deps

* update minor deps

* update major deps

* fix eslint warnings
2019-09-29 14:09:00 -05:00

14 lines
438 B
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
export default function debounce<T extends any[]>(
fn: (...args: T) => unknown,
wait: number = 1000
): (...args: Parameters<typeof fn>) => void {
let timeout: number | undefined;
return function(this: any, ...args): void {
const laterCall = (): unknown => fn.apply(this, args);
window.clearTimeout(timeout);
timeout = window.setTimeout(laterCall, wait);
};
}