* Simple debounce implementation
( fn: Callback, delay: number, )
| 241 | * Simple debounce implementation |
| 242 | */ |
| 243 | function debounce<Callback extends (...args: Parameters<Callback>) => void>( |
| 244 | fn: Callback, |
| 245 | delay: number, |
| 246 | ) { |
| 247 | let timer: ReturnType<typeof setTimeout> | null = null |
| 248 | return (...args: Parameters<Callback>) => { |
| 249 | if (timer) clearTimeout(timer) |
| 250 | timer = setTimeout(() => { |
| 251 | fn(...args) |
| 252 | }, delay) |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Debounce a callback function |