refactor(components): convert components to separate modules

This commit is contained in:
Brandy Carney
2017-03-15 16:06:35 -04:00
parent 5d668036e6
commit ddcd3cf1c5
55 changed files with 1475 additions and 346 deletions

View File

@ -0,0 +1,55 @@
import { NgZone } from '@angular/core';
import { Platform } from '../../platform/platform';
/**
* @hidden
*/
export class DisplayWhen {
isMatch: boolean = false;
conditions: string[];
resizeObs: any;
constructor(conditions: string, public _plt: Platform, public zone: NgZone) {
if (!conditions) return;
this.conditions = conditions.replace(/\s/g, '').split(',');
// check if its one of the matching platforms first
// a platform does not change during the life of an app
for (let i = 0; i < this.conditions.length; i++) {
if (this.conditions[i] && _plt.is(this.conditions[i])) {
this.isMatch = true;
return;
}
}
if (this.orientation()) {
// add window resize listener
this.resizeObs = _plt.resize.subscribe(this.orientation.bind(this));
}
}
orientation(): boolean {
for (let i = 0; i < this.conditions.length; i++) {
if (this.conditions[i] === 'portrait') {
this.isMatch = this._plt.isPortrait();
return true;
}
if (this.conditions[i] === 'landscape') {
this.isMatch = this._plt.isLandscape();
return true;
}
}
return false;
}
ngOnDestroy() {
this.resizeObs && this.resizeObs.unsubscribe();
this.resizeObs = null;
}
}

View File

@ -2,7 +2,7 @@ import { Attribute, Directive, NgZone } from '@angular/core';
import { Platform } from '../../platform/platform';
import { DisplayWhen } from './show-hide-when';
import { DisplayWhen } from './display-when';
/**
* @name HideWhen

View File

@ -0,0 +1,22 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { ShowWhen } from './show-when';
import { HideWhen } from './hide-when';
@NgModule({
declarations: [
ShowWhen,
HideWhen
],
exports: [
ShowWhen,
HideWhen
]
})
export class ShowHideWhenModule {
public static forRoot(): ModuleWithProviders {
return {
ngModule: ShowHideWhenModule, providers: []
};
}
}

View File

@ -1,59 +1,10 @@
import { Attribute, Directive, NgZone } from '@angular/core';
import { DisplayWhen } from './display-when';
import { Platform } from '../../platform/platform';
/**
* @hidden
*/
export class DisplayWhen {
isMatch: boolean = false;
conditions: string[];
resizeObs: any;
constructor(conditions: string, public _plt: Platform, public zone: NgZone) {
if (!conditions) return;
this.conditions = conditions.replace(/\s/g, '').split(',');
// check if its one of the matching platforms first
// a platform does not change during the life of an app
for (let i = 0; i < this.conditions.length; i++) {
if (this.conditions[i] && _plt.is(this.conditions[i])) {
this.isMatch = true;
return;
}
}
if (this.orientation()) {
// add window resize listener
this.resizeObs = _plt.resize.subscribe(this.orientation.bind(this));
}
}
orientation(): boolean {
for (let i = 0; i < this.conditions.length; i++) {
if (this.conditions[i] === 'portrait') {
this.isMatch = this._plt.isPortrait();
return true;
}
if (this.conditions[i] === 'landscape') {
this.isMatch = this._plt.isLandscape();
return true;
}
}
return false;
}
ngOnDestroy() {
this.resizeObs && this.resizeObs.unsubscribe();
this.resizeObs = null;
}
}
/**
*
* @name ShowWhen
@ -111,6 +62,5 @@ export class ShowWhen extends DisplayWhen {
super(showWhen, plt, zone);
}
// ngOnDestroy is implemente in DisplayWhen
// ngOnDestroy is implemented in DisplayWhen
}