ActionChain
The object accepted by store.dispatch()
, thus also the object passed to instance.dispatch()
.
The ActionChain is the key to Zedux's store composition model. ActionChains are just nested objects.
All objects except the innermost contain metadata. Zedux uses certain meta types to know whether actions came from a parent or child store.
The last node in the chain is a normal Action object. An ActionChain that doesn't contain any metadata is thus simply an Action.
That's right. An action is an ActionChain with a size of 1.
ActionChains are not sent to reducers. Zedux unwraps the ActionChain before passing the unwrapped action to the reducer layer.
Definition
interface ActionMeta<Payload = any, Type extends string = string, Data = any> {
metaType: string
metaData?: Data
payload: ActionChain<Payload, Type>
}
type ActionChain<Payload = any, Type extends string = string> =
| ActionMeta<Payload, Type>
| Action<Payload, Type>
ActionMeta
You should never be creating ActionMeta objects yourself, but FYI: ActionMeta objects contain the following fields:
A string. The type of metadata being added to the action.
Can be anything, including undefined. The value depends on the metaType
. For example, Zedux will set this to an array of strings representing a path to a child store when it wants delegate this action to that child store.
Either another ActionMeta node or the wrapped action object if this is the last ActionMeta node in the chain.
Examples
const justAnAction: ActionChain = {
type: 'todos/add',
payload: { text: 'be awesome' },
}
const fromParent: ActionChain = {
metaType: '@@zedux/inherit',
payload: {
type: 'todos/add',
payload: { text: 'be awesome' },
},
}
const fromChild: ActionChain = {
metaType: '@@zedux/delegate',
metaData: ['a', 'b'],
payload: {
type: 'todos/add',
payload: { text: 'be awesome' },
},
}
See Zedux's zeduxTypes
.