1 | const throttle = (fn: () => void, ms: number) => { |
||
2 | let prev: number = 0 |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
3 | |||
4 | return () => { |
||
5 | const now: number = new Date().valueOf() |
||
6 | |||
7 | if (now - prev >= ms) { |
||
8 | fn() |
||
9 | prev = now |
||
10 | } |
||
11 | } |
||
12 | } |
||
13 | |||
14 | export { throttle } |
||
15 |