( options: DebounceStrategyOptions, )
| 26 | * ``` |
| 27 | */ |
| 28 | export function debounceStrategy( |
| 29 | options: DebounceStrategyOptions, |
| 30 | ): DebounceStrategy { |
| 31 | const debouncer = new LiteDebouncer( |
| 32 | (callback: () => Transaction) => callback(), |
| 33 | options, |
| 34 | ) |
| 35 | |
| 36 | return { |
| 37 | _type: `debounce`, |
| 38 | options, |
| 39 | execute: <T extends object = Record<string, unknown>>( |
| 40 | fn: () => Transaction<T>, |
| 41 | ) => { |
| 42 | debouncer.maybeExecute(fn as () => Transaction) |
| 43 | }, |
| 44 | cleanup: () => { |
| 45 | debouncer.cancel() |
| 46 | }, |
| 47 | } |
| 48 | } |