debounceTime
accepts
1
input stream,
time period
number
time period
of silence measured restarts from zerotime period
of silence and then emits the latest value of the input streamreturns a new stream of debounced values
delay
accepts
1
input stream,
time period
number
time period
delayreturns a new stream of timeshifted values
If your stream is created from key presses or mouse movements, you’ll likely deal with bursts of events. But you can’t react to every single event, as it would overload the CPU or flood the servers with too many requests.
A strategy is to wait for a certain “emission silence” window of time (where the user has stopped typing or moving his mouse) to actually handle the latest word or mouse position.
To do so, you can use âťš debounceTime
. Like delay, it waits for a certain time period and delays events. But debounceTime can also ignore events.
They both accept a time period argument, such as 3000
milliseconds.
debounceTime is a rate-limiting operator. It ignores events but also delays others.
The time period is small enough that no events are ignored
With a 3000ms time period, some events are ignored
As the time period gets larger, even more events are ignored
Next
See also
Freelance Developer Advocate. Motion graphics with code. JavaScript and Elm. cedricsoulas.com
Receive my latest news, product updates and programming visualizations. You can unsubscribe at any time.