I have following Angular CLI architecture:
- Core of application consisting of:
- configuration of root state (
NgRx Store
) - auth, router state, feature flags configuration loaded from backend, etc. (everything what all feature modules need) - routing configuration
- dynamic translations library root configuration and other external libraries configuration
- imported store modules (
StoreModule.forFeature
) with entities collections state shared between many lazy loaded feature modules (therefore it is imported intoAppModule
) - REST API communication services
providedIn: 'root'
- they are adapters over communication with backend
- configuration of root state (
- About 30 feature modules, which are lazy loaded via routing - there is no import between them and they are separated from each other
Those entities collections reducers are listening to actions defined in lazy loaded feature modules. For example: module A is loading some entities and put them into collection in core/root state. After some time user navigates into feature module B and resolver decides whether to download entities data (if they are absent in collection) or use already present data and show UI, and in background do refresh.
All actions in application tries to represent unique events in application and they are dispatched only in one place in code, they're not dispatched elsewhere.
My questions are:
- Is it ok to share collections of entities this way?
- Should core reducers listen to actions from lazy loaded feature modules? This is not breaking lazy loading, because I'm importing only actions file, which contains import from
@ngrx/store
to create action creators. Other imports are type imports (import type
) - How to refactor core services and state into Nx Workspace libs?
- How to refactor feature modules into libraries to not to statically import whole libs and broke lazy loading? Keep actions into separate lib or in secondary entry point?