Reputation: 1834
currently the store Im using is a flat stracture of feature modules, i.e:
{
feature_A: {
A:'A',
B:'B'
},
feature_B:{
C:'C',
D:'D'
}
}
But what I want to do is:
{
feature_A: {
A:'A',
B:'B',
feature_B:{
C:'C',
D:'D'
}
}
}
Maybe something like: App.Module
StoreModule.forFeature('feature_A', fromFeature_A.feature_A_Reducers)
StoreModule.forFeature('feature_A.feature_B', fromFeature_B.feature_B_Reducers)
Was searching for an answer for this on the net didn't really find a real anser other than that its recomended to keep a flat structure of the feature modules.
Upvotes: 3
Views: 2399
Reputation: 378
Feature modules in ngrx
are just the immediate state off of the root of the object, so there isn't really an idea of a nested feature module.
Instead, you can accomplish similar behavior by still keeping feature B's state abstracted out into different files (reducers, actions, effects...), but treating it as a sub-state of feature A.
You could then create a selector to access specifically feature B's state:
const selectFeatureA = createFeatureSelector('feature_A');
const selectFeatureB = createSelector(selectFeatureA, (state) => state.feature_B);
Upvotes: 6