condition
Motivation
Condition is very similar to sample
, but allows you to have else
branch along with simple if
matcher.
condition({ source: Unit, if: Store, then?: Unit, else?: Unit })
Formulae
- When
source
is triggered, check value of$checker
, if it equalstrue
, triggerthen
with value fromsource
, otherwise triggerelse
with value fromsource
result
is the same unit assource
allows to nestcondition
to anothercondition
orsample
Arguments
source
(Unit<T>)
— Data from this unit will be passed tothen
orelse
if
(Store<boolean>)
— Updates of this store will not triggerthen
andelse
then
(Unit<T>)
— This unit will be triggered with data fromsource
if$checker
containstrue
. Required ifelse
is not providedelse
(Unit<T>)
— This unit will be triggered with data fromsource
if$checker
containsfalse
. Required ifthen
is not provided
Returns
(Unit<T>)
— The same unit type that passed tosource
Example
condition({ source: Unit<T>, if: T, then?: Unit, else?: Unit })
Formulae
- When
source
is triggered, comparevalue
literal withsource
payload, if it equals triggerthen
with value fromsource
, otherwise triggerelse
with value fromsource
result
is the same unit assource
allows to nestcondition
to anothercondition
orsample
Arguments
source
(Unit<T>)
— Data from this unit will be passed tothen
orelse
if
(T)
— Just value to compare withsource
payload. Note: objects will be compared by referencethen
(Unit<T>)
— This unit will be triggered with data fromsource
if$checker
containstrue
. Required ifelse
is not providedelse
(Unit<T>)
— This unit will be triggered with data fromsource
if$checker
containsfalse
. Required ifthen
is not provided
Returns
(Unit<T>)
— The same unit type that passed tosource
Example
condition({ source: Unit<T>, if: Function, then?: Unit, else?: Unit })
Formulae
- When
source
is triggered, callif
withsource
payload, if it returnstrue
triggerthen
with value fromsource
, otherwise triggerelse
with value fromsource
result
is the same unit assource
allows to nestcondition
to anothercondition
orsample
Arguments
source
(Unit<T>)
— Data from this unit will be passed tothen
orelse
if
((payload: T) => boolean)
— Function comparator. It should return booleanthen
(Unit<T>)
— This unit will be triggered with data fromsource
if$checker
containstrue
. Required ifelse
is not providedelse
(Unit<T>)
— This unit will be triggered with data fromsource
if$checker
containsfalse
. Required ifthen
is not provided
Returns
(Unit<T>)
— The same unit type that passed tosource