throttle
target = throttle(source, timeout)
Motivation
This method allows to trigger target
in equal timeouts regardless of source trigger frequency.
It is useful in live search in UI.
Formulae
- Triggers
target
at most once pertimeout
after triggeringsource
Arguments
source
(Event
|Store
|Effect
) — Source unit, data from this unit used by thetarget
timeout
(number
|Store<number>
) — time to wait before triggertarget
after last trigger orsource
trigger
Returns
target
(Event
) — new event, that triggered each time after triggeringsource
with argument fromsource
Usage
Create event that should be throttled:
Create throttled event from it:
When you call someHappened
it will make throttled call the throttled
event:
Also you can use Effect
and Store
as trigger. throttle
always returns Event
:
throttle({ source, timeout, target })
Motivation
This overload allows to receive target instead of returning it. This is useful when you already have a unit that should be triggered.
Formulae
- Triggers
target
at most once pertimeout
after triggeringsource
Arguments
source
(Event
|Store
|Effect
) — Source unit, data from this unit used by thetarget
timeout
(number
|Store<number>
) — time to wait before triggertarget
after last trigger orsource
triggertarget
(Event
|Store
|Effect
) — Target unit, that triggered each time after triggeringsource
with argument fromsource
Returns
Usage
Example with timeout as store
The new timeout will be used after the previous is over (if there was a delayed target
trigger when the timeout
store changed).
target = throttle({ 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
- Triggers
target
at most once pertimeout
after triggeringsource
Arguments
source
(Event
|Store
|Effect
) — Source unit, data from this unit used by thetarget
timeout
(number
|Store<number>
) — time to wait before triggertarget
after last trigger orsource
trigger
Returns
target
(Event
) — new event, that triggered each time after triggeringsource
with argument fromsource
Usage
Create event that should be throttled:
Create throttled event from it:
When you call someHappened
it will make throttled call the throttled
event:
Also you can use Effect
and Store
as trigger. throttle
always returns Event
: