You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
13 lines
354 B
13 lines
354 B
type Callback<Args extends unknown[]> = (...args: Args) => void;
|
|
|
|
export function debounce<Args extends unknown[]>(
|
|
callback: Callback<Args>,
|
|
wait: number,
|
|
): Callback<Args> {
|
|
let timeoutId: ReturnType<typeof setTimeout>;
|
|
|
|
return (...args: Args) => {
|
|
clearTimeout(timeoutId);
|
|
timeoutId = setTimeout(() => callback(...args), wait);
|
|
};
|
|
}
|
|
|