delay
Method for delaying triggering given unit for some amount of time. Can accept number
, Store<number>
or (sourceValue) => number
(function for calculating timeout based on source
payload) as timeout. Exists in two form: shorthand delay(source, timeout)
and object form delay({source, timeout, target})
, the first one needs to create new unit for this specific purpose, last one needs when target
unit is already exists and the goal is just to call it after delay
delay(source, timeout: number)
Formulae
- When
source
is triggered, wait fortimeout
, then triggertarget
with payload of thesource
Arguments
source
(Event<T>
|Store<T>
|Effect<T>)
— Source unit, data from this unit used to triggertarget
with.timeout
(number)
— time to wait before triggerevent
Returns
target
(Event<T>)
— New event which will receivesource
payload aftertimeout
delay
Example
delay({ source, timeout: number, target })
Formulae
- When
source
is triggered, wait fortimeout
, then triggertarget
with payload of thesource
Arguments
source
(Event<T>
|Store<T>
|Effect<T>)
— Source unit, data from this unit used to triggertarget
with.timeout
(number)
— time to wait before triggerevent
target
(Unit<T>
|Array<Unit<T>>)
— Optional. Target unit or array of units that will be called after delay.
Returns
target
(Unit<T>
|Array<Unit<T>>)
— Target unit or units that were passed todelay
Example
delay(source, timeout: Function)
Motivation
This overload allows to calculate timeout from payload of source
.
It is useful when you know that calculations requires more time if you have more data for payload.
Formulae
- When
source
is triggered, calltimeout
with payload to get the timeout for delay, then triggertarget
with payload of thesource
Arguments
source
(Event<T>
|Store<T>
|Effect<T>)
— Source unit, data from this unit used to triggertarget
with.timeout
((payload: T) => number)
— Calculate delay for eachsource
call. Receives the payload ofsource
as argument. Should returnnumber
— delay in milliseconds.
Returns
target
(Event<T>)
— New event which will receivesource
payload aftertimeout
delay
Example
delay({ source, timeout: Function, target })
Motivation
This overload allows to calculate timeout from payload of source
.
It is useful when you know that calculations requires more time if you have more data for payload.
Formulae
- When
source
is triggered, calltimeout
with payload to get the timeout for delay, then triggertarget
with payload of thesource
Arguments
source
(Event<T>
|Store<T>
|Effect<T>)
— Source unit, data from this unit used to triggertarget
with.timeout
((payload: T) => number)
— Calculate delay for eachsource
call. Receives the payload ofsource
as argument. Should returnnumber
— delay in milliseconds.target
(Unit<T>
|Array<Unit<T>>)
— Optional. Target unit or array of units that will be called after delay.
Returns
target
(Unit<T>
|Array<Unit<T>>)
— Target unit or units that were passed todelay
Example
delay(source, timeout: Store<T>)
Motivation
This overload allows you to read timeout from another store. It is useful when you write music editor and need dynamic delay for your events.
Formulae
- When
source
is triggered, read timeout fromtimeout
store, then triggertarget
with payload of thesource
Arguments
source
(Event<T>
|Store<T>
|Effect<T>)
— Source unit, data from this unit used to triggertarget
with.timeout
(Store<number>)
— Store with number — delay in milliseconds.
Returns
target
(Event<T>)
— New event which will receivesource
payload aftertimeout
delay
Example
delay({ source, timeout: Store<T>, target })
Motivation
This overload allows you to read timeout from another store. It is useful when you write music editor and need dynamic delay for your events.
Formulae
- When
source
is triggered, read timeout fromtimeout
store, then triggertarget
with payload of thesource
Arguments
source
(Event<T>
|Store<T>
|Effect<T>)
— Source unit, data from this unit used to triggertarget
with.timeout
(Store<number>)
— Store with number — delay in milliseconds.target
(Unit<T>
|Array<Unit<T>>)
— Optional. Target unit or array of units that will be called after delay.
Returns
target
(Unit<T>
|Array<Unit<T>>)
— Target unit or units that were passed todelay