CoreModule is an eagerly loaded module containing the state needed at application start.
import * as fromCore from './state/core.reducer';
@NgModule({
...
imports: [
StoreModule.forRoot({ core: fromCore.reducer }),
DocumentModule is a lazy loaded module.
import * as fromDocument from './state/document.reducer';
@NgModule({
...
imports: [
StoreModule.forFeature('document', fromDocument.reducer),
DocumentComponent injects the store.
import * as fromDocument from './state/document.reducer';
constructor(private store: Store<fromDocument.State>) { }
fromDocument.State extends the 'core' state.
import * as fromCore from '../../core/state/core.reducer';
export interface State extends fromCore.State {
document: DocumentState;
}
This is an approach I see used everywhere, but I don't see any benefit to it. When I set it up so that fromDocument.State does not extend fromCore.State, I can still access the 'core' part of the state tree in DocumentComponent.
this.user$ = this.store.select(fromCore.getUser);
By injecting the store in a component I always have access to the complete state tree, regardless how I type the store. So what exactly is the purpose of strongly typing the store? Why not just use Store<any> everywhere? The only way I interact with the store object is store.select and store.dispatch so there is no typing benefit as far as I can see?