1
+ // This is the application's top-level NgModule definition.
2
+ //
3
+ // Think of it as a wirings file: telling Angular where to
4
+ // find our components and services, and telling Angular-redux
5
+ // where to find our reducers, middleware, and epics.
6
+
7
+ // Basic Angular stuff.
1
8
import { BrowserModule } from '@angular/platform-browser' ;
2
9
import { NgModule } from '@angular/core' ;
3
10
import { FormsModule } from '@angular/forms' ;
4
11
import { RouterModule } from '@angular/router' ;
5
12
import { HttpModule } from '@angular/http' ;
6
- import { NgReduxModule } from '@angular-redux/store' ;
7
- import { NgReduxRouterModule } from '@angular-redux/router' ;
8
13
14
+ // Angular-redux ecosystem stuff.
15
+ // @angular -redux/form and @angular-redux/router are optional
16
+ // extensions that sync form and route location state between
17
+ // our store and Angular.
18
+ import { NgReduxModule , NgRedux , DevToolsExtension } from '@angular-redux/store' ;
19
+ import { NgReduxRouterModule , NgReduxRouter , routerReducer } from '@angular-redux/router' ;
20
+ import { provideReduxForms , composeReducers , defaultFormReducer } from '@angular-redux/form' ;
21
+
22
+ // Redux ecosystem stuff.
23
+ import { combineReducers } from 'redux' ;
24
+ import * as createLogger from 'redux-logger' ;
25
+ import { combineEpics , createEpicMiddleware } from 'redux-observable' ;
26
+
27
+ // Top-level app component constructs.
9
28
import { appRoutes } from './app.routes' ;
10
29
import { AppComponent } from './app.component' ;
11
30
import { AppActions } from './app.actions' ;
12
31
32
+ // Elephants module constructs.
13
33
import { ElephantsModule } from './elephants/elephants.module' ;
34
+ import { ElephantsEpics } from './elephants/elephants.epics' ;
35
+ import { elephantsReducer } from './elephants/elephants.reducer' ;
36
+
37
+ // Lions module constructs.
14
38
import { LionsModule } from './lions/lions.module' ;
39
+ import { LionsEpics } from './lions/lions.epics' ;
40
+ import { lionsReducer } from './lions/lions.reducer' ;
41
+
42
+ // Feedback module constructs.
15
43
import { FeedbackModule } from './feedback/feedback.module' ;
16
44
17
45
@NgModule ( {
@@ -30,4 +58,42 @@ import { FeedbackModule } from './feedback/feedback.module';
30
58
providers : [ AppActions ] ,
31
59
bootstrap : [ AppComponent ]
32
60
} )
33
- export class AppModule { }
61
+ export class AppModule {
62
+ constructor (
63
+ private ngRedux : NgRedux < any > ,
64
+ private actions : AppActions ,
65
+ devTools : DevToolsExtension ,
66
+ ngReduxRouter : NgReduxRouter ,
67
+ elephantsEpics : ElephantsEpics ,
68
+ lionsEpics : LionsEpics
69
+ ) {
70
+ // Define the global store shape by combining our application's
71
+ // reducers together into a given structure.
72
+ const rootReducer = composeReducers (
73
+ defaultFormReducer ( ) ,
74
+ combineReducers ( {
75
+ elephants : elephantsReducer ,
76
+ lions : lionsReducer ,
77
+ router : routerReducer ,
78
+ } ) ) ;
79
+
80
+ // Tell Redux about our reducers and epics. If the Redux DevTools
81
+ // chrome extension is available in the browser, tell Redux about
82
+ // it too.
83
+ ngRedux . configureStore (
84
+ rootReducer ,
85
+ { } ,
86
+ [
87
+ createLogger ( ) ,
88
+ createEpicMiddleware ( combineEpics ( ...elephantsEpics . epics ) ) ,
89
+ createEpicMiddleware ( combineEpics ( ...lionsEpics . epics ) ) ,
90
+ ] ,
91
+ devTools . isEnabled ( ) ? [ devTools . enhancer ( ) ] : [ ] ) ;
92
+
93
+ // Enable syncing of Angular router state with our Redux store.
94
+ ngReduxRouter . initialize ( ) ;
95
+
96
+ // Enable syncing of Angular form state with our Redux store.
97
+ provideReduxForms ( ngRedux ) ;
98
+ }
99
+ }
0 commit comments