split
Choose one of cases by given conditions. It "splits" source unit into several events, which fires when payload matches their conditions. Works like pattern matching for payload values and external stores
#
Concepts#
Case modeMode in which target case is selected by name of it's field. Case could be selected from data in source
by case function or from external case store which keept current case name. After selection data from source
will be sent to corresponding cases[fieldName]
(if there is one), if none of the fields matches, then the data will be sent to cases.__
(if there is one)
See also:
#
Matching modeMode in which each case sequentially matched by stores and functions in fields of match
object.
If one of the fields got true
from store value or return of function, then the data from source
will be sent to corresponding cases[fieldName]
(if there is one), if none of the fields matches, then the data will be sent to cases.__
(if there is one)
See also:
#
Case storeStore with string which will be used to choose case by it's name. Placed directly in match
field
#
Case functionString-returning function which will be called with value from source
to choose case by it's name. Placed directly in match
field, should be pure
#
Matcher storeBoolean store which indicates whether to choose particular case or try next one. Placed in fields of match
object, might be mixed with matcher functions
#
Matcher functionBoolean-returning function which indicates whether to choose particular case or try next one. Placed in fields of match
object, might be mixed with matcher stores, should be pure
note
Case store, case funtion and matcher store are supported since effector 21.8.0
#
split with casesArguments
source
: Unit which will trigger computation insplit
match
: Single store with string, single function which returns string or object with boolean stores and functions which returns booleancases
: Object with units to which data will be passed fromsource
after case selection
Returns
since
effector 21.0.0
#
Example 1#
Example 2You can match directly to store api as well:
#
split without explicit casesArguments
source
: Unit which will trigger computation insplit
match
(Object): Schema of cases, which uses names of resulting events as keys, and matching function((value) => Boolean)
Returns
(Object) - Object, having keys, defined in match
argument, plus __
(two underscores) - which stands for default
(no matches met) case.
since
effector 20.0.0
#
Example 1note
Only the first met match will trigger resulting event