From d3370e266a49fa03e3695af07853722d7b5c84c1 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Tue, 13 Dec 2016 12:03:04 +0100 Subject: [PATCH] fixed an issue where the reducers wouldn't be combined correctly when using AoT compilation --- src/app/app.module.ts | 4 ++-- src/app/app.reducers.ts | 21 +++++++++++++++++---- src/app/header/header.component.ts | 4 +--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5264b8bee6..ead69d94f0 100755 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -11,7 +11,7 @@ import { StoreModule } from "@ngrx/store"; import { RouterStoreModule } from "@ngrx/router-store"; import { StoreDevtoolsModule } from "@ngrx/store-devtools"; -import { reducers } from './app.reducers'; +import { rootReducer } from './app.reducers'; import { effects } from './app.effects'; @NgModule({ @@ -30,7 +30,7 @@ import { effects } from './app.effects'; * meta-reducer. This returns all providers for an @ngrx/store * based application. */ - StoreModule.provideStore(reducers), + StoreModule.provideStore(rootReducer), /** * @ngrx/router-store keeps router state up-to-date in the store and uses diff --git a/src/app/app.reducers.ts b/src/app/app.reducers.ts index 95d24041b2..deb75dd06a 100644 --- a/src/app/app.reducers.ts +++ b/src/app/app.reducers.ts @@ -1,7 +1,20 @@ -import { headerReducer } from './header/header.reducer'; -import { hostWindowReducer } from "./shared/host-window.reducer"; +import { combineReducers } from "@ngrx/store"; +import { routerReducer, RouterState } from "@ngrx/router-store"; +import { headerReducer, HeaderState } from './header/header.reducer'; +import { hostWindowReducer, HostWindowState } from "./shared/host-window.reducer"; + +export interface AppState { + router: RouterState; + hostWindow: HostWindowState; + header: HeaderState; +} export const reducers = { - headerReducer, - hostWindowReducer + router: routerReducer, + hostWindow: hostWindowReducer, + header: headerReducer +}; + +export function rootReducer(state: any, action: any) { + return combineReducers(reducers)(state, action); } diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts index 18389a099c..69da1aea68 100644 --- a/src/app/header/header.component.ts +++ b/src/app/header/header.component.ts @@ -19,9 +19,7 @@ export class HeaderComponent implements OnInit { } ngOnInit(): void { - this.isNavBarCollapsed = this.store.select('headerReducer') - //ensure that state is not null, can happen when using AoT compilation - .filter((state: HeaderState) => state !== null && state !== undefined) + this.isNavBarCollapsed = this.store.select('header') //unwrap navCollapsed .map(({ navCollapsed }: HeaderState) => navCollapsed); }