spread
source = spread(targets)
Motivation
This method allows to trigger many target at once, if they match the source structure. It is useful when you need to destructure object and save values to different stores.
Formulae
- When
source
is triggered with object, extractfield
from data, and triggertarget
targets
can have multiple properties- If the
source
was triggered with non-object, nothing would be happening - If
source
is triggered with object but without propertyfield
, target for thisfield
will not be triggered
Arguments
targets
(Record<string, Event<T> | Store<T> | Effect<T>>)
— Flat object which key is key insource
payload, and value is unit to store value to.
Returns
source
(Event<T>)
— Source event, data passed to it should be an object with fields fromtargets
Example
Conditionally save value to stores
Nested spreading
spread({ source, targets })
Motivation
This method allows to trigger many target at once, if they match the source structure. It is useful when you need to destructure object and save values to different stores.
Formulae
- When
source
is triggered with object, extractfield
from data, and triggertarget
targets
can have multiple properties- If the
source
was triggered with non-object, nothing would be happening - If
source
is triggered with object but without propertyfield
, target for thisfield
will not be triggered
Arguments
source
(Event<T>
|Store<T>
|Effect<T>)
— Source unit, data passed to it should be an object with fields fromtargets
targets
(Record<string, Event<T> | Store<T> | Effect<T>>)
— Flat object which key is key insource
payload, and value is unit to store value to.
Example
Save fields of payload to different stores
Call events on store changes
source = spread({ targets })
Motivation
This overload receives targets
as an object. May be useful for additional clarity, but it’s longer to write
Formulae
- When
source
is triggered with object, extractfield
from data, and triggertarget
targets
can have multiple properties- If the
source
was triggered with non-object, nothing would be happening - If
source
is triggered with object but without propertyfield
, target for thisfield
will not be triggered
Arguments
targets
(Record<string, Event<T> | Store<T> | Effect<T>>)
— Flat object which key is key insource
payload, and value is unit to store value to.
Returns
source
(Event<T>)
— Source event, data passed to it should be an object with fields fromtargets
source = spread({ targets: { field: Unit[] } })
Motivation
Multiple units can be passed for each target field
Formulae
- When
source
is triggered with object, extractfield
from data, and trigger all targets oftarget
targets
can have multiple properties with multiple units- If the
source
was triggered with non-object, nothing would be happening - If
source
is triggered with object but without propertyfield
, no unit of the target for thisfield
will be triggered