header, isNavBarCollapsed observable: filter out undefined state that can occur when using AoT compilation

This commit is contained in:
Art Lowel
2016-12-13 10:14:47 +01:00
parent 54f3cbc41b
commit 2846dc9446
5 changed files with 15 additions and 4 deletions

View File

@@ -37,6 +37,13 @@ export class AppComponent implements OnDestroy, OnInit {
translate.setDefaultLang('en'); translate.setDefaultLang('en');
// the lang to use, if the lang isn't available, it will use the current loader to get them // the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use('en'); translate.use('en');
this.onResize({
target: {
innerWidth: 800,
innerHeight: 600
}
});
} }
ngOnInit() { ngOnInit() {

View File

@@ -1,6 +1,6 @@
import { EffectsModule } from "@ngrx/effects"; import { EffectsModule } from "@ngrx/effects";
import { HeaderEffects } from "./header/header.effects"; import { HeaderEffects } from "./header/header.effects";
export default [ export const effects = [
EffectsModule.run(HeaderEffects) EffectsModule.run(HeaderEffects)
]; ];

View File

@@ -11,8 +11,8 @@ import { StoreModule } from "@ngrx/store";
import { RouterStoreModule } from "@ngrx/router-store"; import { RouterStoreModule } from "@ngrx/router-store";
import { StoreDevtoolsModule } from "@ngrx/store-devtools"; import { StoreDevtoolsModule } from "@ngrx/store-devtools";
import reducers from './app.reducers'; import { reducers } from './app.reducers';
import effects from './app.effects'; import { effects } from './app.effects';
@NgModule({ @NgModule({
declarations: [ declarations: [

View File

@@ -1,7 +1,7 @@
import { headerReducer } from './header/header.reducer'; import { headerReducer } from './header/header.reducer';
import { hostWindowReducer } from "./shared/host-window.reducer"; import { hostWindowReducer } from "./shared/host-window.reducer";
export default { export const reducers = {
headerReducer, headerReducer,
hostWindowReducer hostWindowReducer
} }

View File

@@ -3,6 +3,7 @@ import { Store } from "@ngrx/store";
import { HeaderState } from "./header.reducer"; import { HeaderState } from "./header.reducer";
import { HeaderActions } from "./header.actions"; import { HeaderActions } from "./header.actions";
import { Observable } from "rxjs"; import { Observable } from "rxjs";
import 'rxjs/add/operator/filter';
@Component({ @Component({
selector: 'ds-header', selector: 'ds-header',
@@ -19,6 +20,9 @@ export class HeaderComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.isNavBarCollapsed = this.store.select('headerReducer') 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)
//unwrap navCollapsed
.map(({ navCollapsed }: HeaderState) => navCollapsed); .map(({ navCollapsed }: HeaderState) => navCollapsed);
} }