diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-21 11:19:10 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-21 11:19:10 +0800 |
| commit | 679bee512ec088ceab59df0f6683fe8a240866e7 (patch) | |
| tree | c4205d588ed130e923c31afec23944b3e87f4aa6 /src | |
| parent | fac2394e4de241a202afbe9274eeddfbc6ad2942 (diff) | |
feat: allow throttle set delays by function
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils.mjs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/utils.mjs b/src/utils.mjs index 8162aa6..3eb57bb 100644 --- a/src/utils.mjs +++ b/src/utils.mjs | |||
| @@ -76,9 +76,12 @@ export function throttle(func, delay) { | |||
| 76 | 76 | ||
| 77 | return (...args) => { | 77 | return (...args) => { |
| 78 | if (timerFlag !== null) return null | 78 | if (timerFlag !== null) return null |
| 79 | timerFlag = setTimeout(() => { | 79 | |
| 80 | timerFlag = null; | 80 | timerFlag = setTimeout( |
| 81 | }, delay); | 81 | () => timerFlag = null, |
| 82 | typeof delay === 'function' ? delay() : delay | ||
| 83 | ); | ||
| 84 | |||
| 82 | return func(...args); | 85 | return func(...args); |
| 83 | }; | 86 | }; |
| 84 | } | 87 | } |