-
Notifications
You must be signed in to change notification settings - Fork 5
/
core.module.ts
67 lines (63 loc) · 2.06 KB
/
core.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { environment } from '../../environments/environment'
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from "@angular/core"
import { HttpClientModule } from '@angular/common/http'
import { BrowserModule } from '@angular/platform-browser'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { StoreModule, USER_PROVIDED_META_REDUCERS } from '@ngrx/store'
import { EffectsModule } from '@ngrx/effects'
import { RouterStateSerializer, StoreRouterConnectingModule } from '@ngrx/router-store'
import { StoreDevtoolsModule } from '@ngrx/store-devtools'
import { reducers } from './reducers/root.reducers'
import { metaReducersFactory } from './reducers/meta.reducers'
import { RouterSimpleStateSerializer } from './serializers/router-state.serializer'
import { LocalStorageService } from './services/local-storage.service'
/**
* @name CoreModule
* @description A wrapper module for global services, basic Angular stuff, and NgRX setup
* Only to be imported at the root module level (only import this once)
*/
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
StoreModule.forRoot(reducers),
EffectsModule.forRoot([]),
StoreDevtoolsModule.instrument({
maxAge: 20,
logOnly: environment.production
}),
StoreRouterConnectingModule.forRoot()
],
providers: [
{
provide: RouterStateSerializer,
useClass: RouterSimpleStateSerializer
},
{
provide: USER_PROVIDED_META_REDUCERS,
deps: [LocalStorageService],
useFactory: metaReducersFactory
}
],
exports: [
BrowserModule,
BrowserAnimationsModule,
HttpClientModule
]
})
export class CoreModule {
constructor (@Optional() @SkipSelf() parentModule: CoreModule) {
if (parentModule) {
throw new Error(
'Import CoreModule only once in the Root Module, probably AppModule');
} else {
console.log('[CoreModule] constructor()')
}
}
static forRoot(): ModuleWithProviders<CoreModule> {
return {
ngModule: CoreModule
}
}
}