reducerFactory
function for turning an action reducer
map into an action reducer.Store
such that a child module's services and components only have access to the state of that module.At the core this is still redux making it easy to instrument, rehydrate, etc.
Root module:
@NgModule({
imports: [
StoreModule.forRoot({ todos: todoReducer, layout: layoutReducer }, {
initialState?: { ... },
reducerFactory?: combineReducers
})
]
})
export class AppModule { }
Global state shape:
{
todos: { ... },
layout: { ... }
}
Child module:
@NgModule({
imports: [
StoreModule.forFeature('feature', { blog: blogReducer }, {
initialState?: { ... },
reducerFactory?: combineReducers
})
]
})
export class FeatureModule { }
New global state shape:
{
todos: { ... },
layout: { ... },
feature: {
blog: { ... }
}
}
Injecting Store
in a component or service belonging to FeatureModule
only gives you access to the local state:
{
blog: { ... }
}
I have a rough but complete implementation available in a branch here: https://github.com/MikeRyan52/store/tree/feat/fractal-statemanagement