splitMap
shape = splitMap({ source, cases })
Motivation
The method is a combination of split
and map
.
It is useful when you want add some kind of pattern matching.
Formulae
- On each
source
trigger, call each function incases
object one after another until function returns non undefined, and call event inshape
with the same name as function incases
object. - If no function returned value event
__
inshape
should be triggered
Arguments
source
(Event
|Store
|Effect
) — Source unit, data from this unit passed to each function incases
object and__
event inshape
as iscases
({ [key: string]: (payload: T) => any | void }
) — Object of functions. Function receives one argument is a payload fromsource
, should return any value orundefined
Returns
shape
({ [key: string]: Event<any>; __: Event<T> }
) — Object of events, with the same structure ascases
, but with the default event__
, that triggered when each other function returnsundefined