rewrote window resize event using redux

This commit is contained in:
Art Lowel
2016-12-12 16:02:27 +01:00
parent 69f8d9855a
commit 20632a8d12
10 changed files with 88 additions and 26 deletions

View File

@@ -3,10 +3,13 @@ import {
ChangeDetectionStrategy,
ViewEncapsulation,
OnDestroy,
OnInit
OnInit, HostListener
} from "@angular/core";
import { Router } from "@angular/router";
import { TranslateService } from "ng2-translate";
import { HostWindowState } from "./shared/host-window.reducer";
import { Store } from "@ngrx/store";
import { HostWindowActions } from "./shared/host-window.actions";
@Component({
changeDetection: ChangeDetectionStrategy.Default,
@@ -27,7 +30,8 @@ export class AppComponent implements OnDestroy, OnInit {
constructor(
private translate: TranslateService,
private router: Router
private router: Router,
private store: Store<HostWindowState>
) {
// this language will be used as a fallback when a translation isn't found in the current language
translate.setDefaultLang('en');
@@ -47,4 +51,11 @@ export class AppComponent implements OnDestroy, OnInit {
}
}
@HostListener('window:resize', ['$event'])
private onResize(event): void {
this.store.dispatch(
HostWindowActions.resize(event.target.innerWidth, event.target.innerHeight)
);
}
}