Dispatches an action, technically it calls reducer with an optional payload.
The dispatch
method is available in
- store’s instance
- reducers and
- middlewares
In Plain form:
dispatch(action, payload, dispatchConfig? )
In Typescript form:
type TDynaduxDispatch<TPayload = any> = <TPayload>(action: string, payload?: TPayload) => void;
The dispatcher is a simple method with 2 arguments.
- 1st (required), the action, where is a string
- 2nd (optional) is the payload, could be anything, a string, a number, an object, null.
- 3rd (optional) a dispatch configuration
For example:
store.dispatch(‘login-user’, {loginName: ‘[email protected]’, psw:’123@456’})
store.dispatch(action.USER_LOGIN, userInfo);
store.dispatch(action.USER_LOGOFF);
This small config object that currently has only one attribute.
Dynadux by default calls the onChange
when the reducer, or a middleware returns a partial state.
When you want a dispatch to do not call the onChange
of the store, set the blockChange
to true
.
For example:
store.dispatch(action.UPDATE_METADATA, {meta}, {blockChange: true}); // Block the onChange callback call
store.dispatch(action.UPDATE_CONFIG, config); // This is will trigger the change as normal
store.dispatch(action.SOMETHING_ELSE);
Note:
- middlewares still are called
onDispatch
callback still is called