refactor(all): cosmetic changes + app.resize as event emitter

This commit is contained in:
Manu Mtz.-Almeida
2017-02-16 16:02:55 +01:00
parent f577e54f38
commit be0b6a8872
12 changed files with 103 additions and 119 deletions

View File

@ -9,6 +9,7 @@ import { Platform } from '../../platform/platform';
export class DisplayWhen {
isMatch: boolean = false;
conditions: string[];
resizeObs: any;
constructor(conditions: string, public _plt: Platform, public zone: NgZone) {
if (!conditions) return;
@ -26,12 +27,7 @@ export class DisplayWhen {
if (this.orientation()) {
// add window resize listener
_plt.onResize(() => {
zone.run(() => {
this.orientation();
});
});
return;
this.resizeObs = _plt.resize.subscribe(this.orientation.bind(this));
}
}
@ -49,8 +45,13 @@ export class DisplayWhen {
return true;
}
}
return false;
}
ngOnDestroy() {
this.resizeObs && this.resizeObs.unsubscribe();
this.resizeObs = null;
}
}
/**
@ -110,6 +111,8 @@ export class ShowWhen extends DisplayWhen {
super(showWhen, plt, zone);
}
// ngOnDestroy is implemente in DisplayWhen
}
/**
@ -169,4 +172,6 @@ export class HideWhen extends DisplayWhen {
super(hideWhen, plt, zone);
}
// ngOnDestroy is implemente in DisplayWhen
}