1 parent 263d191 commit afdd3f3Copy full SHA for afdd3f3
1 file changed
src/utils/debounce.ts
@@ -0,0 +1,18 @@
1
+export function debounce<T extends (...args: any[]) => void>(fn: T, delayMs: number): T {
2
+ let timer: any;
3
+ return ((...args: any[]) => {
4
+ clearTimeout(timer);
5
+ timer = setTimeout(() => fn(...args), delayMs);
6
+ }) as T;
7
+}
8
+
9
+export function throttle<T extends (...args: any[]) => void>(fn: T, intervalMs: number): T {
10
+ let lastCall = 0;
11
12
+ const now = Date.now();
13
+ if (now - lastCall >= intervalMs) {
14
+ lastCall = now;
15
+ fn(...args);
16
+ }
17
18
0 commit comments