Function
throttle
(
func: T,
interval: number
)
Source from the content-addressed store, hash-verified
| 41 | }; |
| 42 | |
| 43 | export const throttle = <T extends (...args: any[]) => any>( |
| 44 | func: T, |
| 45 | interval: number |
| 46 | ) => { |
| 47 | let timer: Timeout | null = null; |
| 48 | |
| 49 | return function f( |
| 50 | this: unknown, |
| 51 | ...args: Parameters<T> |
| 52 | ): ReturnType<T> | undefined { |
| 53 | if (timer) { |
| 54 | return; |
| 55 | } |
| 56 | func.call(this, ...args); |
| 57 | timer = setTimeout(() => (timer = null), interval); |
| 58 | }; |
| 59 | }; |
| 60 | |
| 61 | export const debounce = <T extends (...args: any[]) => any>( |
| 62 | func: T, |
Tested by
no test coverage detected