Dispatcher
Dispatcher are async functions that receive a reducer and, in addition some arguments that will be passed to the reducer. This the one way to modify the store. Like react.setState
dispatch
is async. Use await
keyword to make things after a dispatch. There is 2 ways to dispatch
:
Using the
dispatch
method direcltyCalling a dispatcher created by
createDispatcher
orcreateDispatchers
Dispatching will trigger middlewares and will rerender all connected components that are wrapped by the connect
HOC of a same RxStore instance (think singleton).
async dispatch(reducer)
dispatch(reducer)
Using dispatch
method directly. Be aware with this method. It can generate a lot of boilerplate code. To reduce it, see createDispatchers
Example
todo.reducers.js
todo.addInput.container.jsx
createDispatcher(reducer, ...rest)
createDispatcher(reducer, ...rest)
createDispatcher
is more like a built-in helper to reduce repetitive code around dispatch
;
Example
todo.reducers.js
todo.dispatchers.js
todo.addInput.container.jsx
createDispatchers(mapReducers:Object<key,reducer>):Object<key, dispatcher>
createDispatchers(mapReducers:Object<key,reducer>):Object<key, dispatcher>
createDispatchers
is more like a built-in helper to reduce repetitive code around createDispatcher
.
Example
todo.reducers.js
todo.addInput.container.jsx
Last updated