This method allows you to get state from each passed store and combine it to single value and save to single store, that updates every time like each passed store.
combine(...stores, fn)#
Formulae#
- After call
combine, state of each store is extracted and passed to function arguments,resultof a function call will be state of store$result - Any amount of stores can be passed to
combine, but latest argument always should be function-reducer that returns new state - If function returned the same
resultas previous, store$resultwill not be triggered - If several stores updated at the same time (during one tick) there will be single call of function and single update of
$resultstore
Returns
Store: New store
Example#
combine({ A, B, C }, fn?)#
Formulae#
- Read state from stores
$first,$second,$thirdand assign it to propertiesa,b,caccordingly, that object will be saved to$resultstore - Store
$resultcontain object{a, b, c}and will be updated on each update of passed stores - If several stores updated at the same time (during one tick) there will be single update of
$resultstore
Formulae with fn#
- Read state from stores
$first,$second,$thirdand assign it to propertiesa,b,caccordingly, calls function with that object - The
resultof the function call saved in$resultstore - If function returned the same
resultas previous, store$resultwill not be triggered - If several stores updated at the same time (during one tick) there will be single call of function and single update of
$resultstore
Returns
Store: New store
note
Formerly known as createStoreObject
Example#
combine([A, B, C], fn?)#
Formulae#
- Read state from stores
$first,$second,$thirdand assign it to array with the same order as passed stores, calls function with that array - The
resultof the function call saved in$resultstore - If function returned the same
resultas previous, store$resultwill not be triggered - If several stores updated at the same time (during one tick) there will be single call of function and single update of
$resultstore
Formulae without fn#
- Read state from stores
$first,$second,$thirdand assign it to array with the same order as passed stores, that array will be saved to$resultstore - Store
$resultwill be updated on each update of passed stores - If several stores updated at the same time (during one tick) there will be single update of
$resultstore
Returns
Store: New store