mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 20:25:43 +00:00
16 lines
401 B
TypeScript
16 lines
401 B
TypeScript
export const debounce = <F extends (...args: any[]) => any>(
|
|
func: F,
|
|
delay: number
|
|
): ((...args: Parameters<F>) => void) => {
|
|
let timeoutId: ReturnType<typeof setTimeout> | null;
|
|
return function debounced(...args: Parameters<F>) {
|
|
if (timeoutId) {
|
|
clearTimeout(timeoutId);
|
|
}
|
|
timeoutId = setTimeout(() => {
|
|
func(...args);
|
|
timeoutId = null;
|
|
}, delay);
|
|
};
|
|
};
|