LINEAR
npm install linear-debounce
Multiple debounce actions sequencer
Linear allows debouncing more than one function at a time, making it simple to respond to one event with multiple functions, or at different times:
window;
It is also possible to pass multiple functions to fire on the same delay using an array of functions:
window;
Sometimes you would want to cancel the already initiated events from being fired, for example, when your app's state changes and you do not expect the debounced actions anymore. To cancel the events, simply call cancel
:
const isTypingDebouncer = ; ; // initiates the debounced actions isTypingDebouncer; // clears existing timeouts, in our case, only `0` will fire.
Note: Calling cancel
will not prevent future timeouts from being created. It only clears the ones that have already initiated. Calling isTypingDebouncer
again, for example, will re-start the count.