import { CommonModule } from '@angular/common' ; import { ModuleWithProviders , NgModule , Optional , SkipSelf } from '@angular/core' ; import { MatDialogModule , MatSnackBarModule } from '@angular/material' ; import { EffectsModule } from '@ngrx/effects' ; import { RouterStateSerializer , StoreRouterConnectingModule } from '@ngrx/router-store' ; import { StoreModule } from '@ngrx/store' ; import { StoreDevtoolsModule } from '@ngrx/store-devtools' ; import { environment } from '../../environments/environment' ; import { appMetaReducers , appReducer } from './app.reducer' ; import { CustomerEffects } from './customer/customer.effects' ; import { LineItemEffects } from './line-item/line-item.effects' ; import { OrderEffects } from './order/order.effects' ; import { ProductEffects } from './product/product.effects' ; import { CustomRouterStateSerializer } from './shared/utils' ; @ NgModule ( { imports : [ CommonModule , MatDialogModule , MatSnackBarModule , StoreRouterConnectingModule , StoreModule . forRoot ( appReducer , { metaReducers : appMetaReducers } ) , EffectsModule . forRoot ( [ CustomerEffects , ProductEffects , OrderEffects , LineItemEffects ] ) , ! environment . production ? StoreDevtoolsModule . instrument ( ) : [ ] ] , declarations : [ ] } ) export class StateModule { static forRoot ( ) { return { ngModule : StateModule , providers : [ { provide : RouterStateSerializer , useClass : CustomRouterStateSerializer } ] } ; } constructor ( @ Optional ( ) @ SkipSelf ( ) parentModule ) { if ( parentModule ) { throw new Error ( 'StateModule is already loaded. Import it in the AppModule only' ) ; } } }