ldc-cocotte/resources/ts/modules/debounce.ts

14 lines
337 B
TypeScript
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
type SetTimeoutReturn = ReturnType<typeof setTimeout>
export function defineDebounce<Args>(
fn: (...args: Args[]) => void,
delay: number = 600
): (...args: Args[]) => void {
let timeoutId: SetTimeoutReturn;
return (...args: Args[]) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn(...args), delay);
};
}