I am new to NgRx.
In my project We have 3 levels of lazy Modules. I want the store's state to be nested according to the modules hierarchy but when I am writing: storeModule.forFeature('child',reducer)
I am getting a flat slice of state instead of hierarchical one.
For example if I have parent module and a child module. I will define at the parent Module storeModule.forFeature('father',reducer)
and in the child module storeModure.forFeature('child',reducer)
the result of the state will not be
{ father { child {}}}
rather it will be:
{ father {}, child {}}
Is there a way to make the state hierarchical as the way the lazy modules are?
You actually can have lazy loaded state slices. Imagine you have the following module configuration
And you want (as you described) to have the following state
You need to ensure that:
AppModuleand a Router in theFatherModule.FatherModulein theAppModulesrouter(!).ChildModulein theFatherModulesrouter(!).ChildModule:StoreModule.forFeature('child', childreducers)and in theFatherModule:StoreModule.forFeature('father', fatherreducers).For example if you navigate to a component in the
FatherModuleit'll load thefatherfeature. But not necessarily thechildfeature. Only if you navigate to some subroute which loads theChildModule.What you currently do is having both
forFeaturemethods in the same module. That does not make any sense because the "feature" is directly related to the module.