HierarchyDescriptor
The type passed to createStore()
and to Store#use()
. The hierarchy descriptor describes the store's state tree. Zedux reads the hierarchy and converts it into a tree of reducers, one for each "branch" (nested object) in the tree.
Zedux also finds all child stores and wraps them in special reducers that know how to keep the state in sync between the child store and the parent's state slice that the child controls.
Definition
type Branch<T = any> = {
[K in keyof T]: HierarchyDescriptor<T[K]>
}
type HierarchyDescriptor<State = any> =
| Branch<State>
| Store<State>
| Reducer<State>
| null
In English: A HierarchyDescriptor can be a store, a reducer, or an object containing stores, reducers, or more objects nested indefinitely.
import { createStore } from '@zedux/react'
const withStore = createStore(myStore)
const withReducer = createStore(myReducer)
const withObject = createStore({
storeState: myStore,
reducerState: myReducer,
})
const nested = createStore({
a: {
b: storeB,
c: storeC,
d: {
e: reducerE,
f: storeF,
},
},
})
Any node in the HierarchyDescriptor can also be set to null
. This indicates removal when passed to Store#use()
.
const myStore = createStore({
a: storeA,
b: storeB,
})
myStore.use({
b: null, // remove `b` from myStore
})
note
Passing null
doesn't do anything in HierarchyDescriptors passed to createStore()
.