Skip to content

Commit 7bc4289

Browse files
committed
feat(core): create core module and import @ngrx/*
1 parent 5c687fe commit 7bc4289

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

src/app/app-routing.module.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
2+
import { NgModule } from '@angular/core';
3+
4+
const routes: Routes = [];
5+
6+
@NgModule({
7+
imports: [
8+
RouterModule.forRoot(routes, {
9+
scrollPositionRestoration: 'enabled',
10+
preloadingStrategy: PreloadAllModules,
11+
}),
12+
],
13+
exports: [RouterModule],
14+
})
15+
export class AppRoutingModule {}

src/app/app.module.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@ import { BrowserModule } from '@angular/platform-browser';
44
import { NgModule } from '@angular/core';
55

66
import { AppComponent } from './app/app.component';
7+
import { AppRoutingModule } from './app-routing.module';
8+
import { CoreModule } from './core/core.module';
79

810
@NgModule({
911
declarations: [AppComponent],
1012
imports: [
13+
// Angular
1114
BrowserModule,
12-
TuiRootModule,
1315
BrowserAnimationsModule,
16+
17+
// Taiga UI
18+
TuiRootModule,
1419
TuiDialogModule,
1520
TuiNotificationsModule,
21+
22+
// Core
23+
CoreModule,
24+
25+
// Routing
26+
AppRoutingModule,
1627
],
1728
providers: [],
1829
bootstrap: [AppComponent],

src/app/core/core.module.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { NgModule, Optional, SkipSelf } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { EffectsModule } from '@ngrx/effects';
4+
import { HttpClientModule } from '@angular/common/http';
5+
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
6+
import { StoreModule } from '@ngrx/store';
7+
import { StoreRouterConnectingModule } from '@ngrx/router-store';
8+
9+
import { environment } from '../../environments/environment';
10+
11+
@NgModule({
12+
imports: [
13+
// Angular
14+
CommonModule,
15+
HttpClientModule,
16+
17+
// NgRx
18+
StoreModule.forRoot({}, {}),
19+
StoreRouterConnectingModule.forRoot(),
20+
EffectsModule.forRoot([]),
21+
environment.production
22+
? []
23+
: StoreDevtoolsModule.instrument({ name: 'Angular Authentication' }),
24+
],
25+
exports: [],
26+
})
27+
export class CoreModule {
28+
constructor(
29+
@Optional()
30+
@SkipSelf()
31+
parentModule: CoreModule
32+
) {
33+
if (parentModule) {
34+
throw new Error('CoreModule is already loaded. Import only once in AppModule');
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)