debounce
debounce(source, timeout)
Motivation
Method creates a new event, that will be triggered after some time. It is useful for handling user events such as scrolling, mouse movement, or keypressing. It is useful when you want to pass created event immediately to another method as argument.
Formulae
- Wait for
timeout
after the last timesource
was triggered, then triggerevent
with payload of thesource
Arguments
source
(Event<T>
|Store<T>
|Effect<T>)
— Source unit, data from this unit used by theevent
timeout
(number | Store<number>)
— time to wait before triggerevent
Returns
event
(Event<T>)
— New event, that triggered after delay
Example
Example with timeout as store
debounce({ source, timeout, target })
Motivation
This overload receives target as argument, that will be triggered after timeout. It is useful when you already have an unit that you need to trigger.
Formulae
- Wait for
timeout
after the last timesource
was triggered and calltarget
with data from thesource
Arguments
source
(Event<T>
|Store<T>
|Effect<T>)
— Source unit, data from this unit used to triggertarget
with payload of thesource
timeout
(number | Store<number>)
— time to wait before triggerevent
target
(Event<T>
|Store<T>
|Effect<T>)
— Target unit, data from thesource
will be passed to this unit
Returns
target
(Event<T>
|Store<T>
|Effect<T>)
— Target unit that was passed to input argumenttarget
Example
debounce({ source, timeout })
Motivation
This overload receives source
and timeout
as an object. May be useful for additional clarity, but it’s longer to write
Formulae
- Wait for
timeout
after the last timesource
was triggered, then triggerevent
with payload of thesource
Arguments
source
(Event<T>
|Store<T>
|Effect<T>)
— Source unit, data from this unit used by theevent
timeout
(number | Store<number>)
— time to wait before triggerevent
Returns
event
(Event<T>)
— New event, that triggered after delay