feat(prodMode): set isProd() when prodMode set in @App config

This commit is contained in:
Adam Bradley
2016-02-21 13:01:31 -06:00
parent 5302d63b54
commit 3c8daa0781
3 changed files with 39 additions and 25 deletions

View File

@ -13,13 +13,12 @@ import {rafFrames} from '../../util/dom';
*/ */
@Injectable() @Injectable()
export class IonicApp { export class IonicApp {
private _titleSrv: Title = new Title(); private _cmps: {[id: string] : any} = {};
private _title: string = '';
private _disTime: number = 0; private _disTime: number = 0;
private _scrollTime: number = 0; private _scrollTime: number = 0;
private _title: string = '';
// Our component registry map private _titleSrv: Title = new Title();
private components: {[id: string] : any} = {}; private _isProd: boolean = false;
constructor( constructor(
private _config: Config, private _config: Config,
@ -32,18 +31,29 @@ export class IonicApp {
* @param {string} val Value to set the document title to. * @param {string} val Value to set the document title to.
*/ */
setTitle(val: string) { setTitle(val: string) {
let self = this; if (val !== this._title) {
if (val !== self._title) { this._title = val;
self._title = val; this._titleSrv.setTitle(val);
this._zone.runOutsideAngular(() => {
function setAppTitle() {
self._titleSrv.setTitle(self._title);
}
rafFrames(4, setAppTitle);
});
} }
} }
/**
* Returns if the app has been set to be in be in production mode or not.
* Production mode can only be set within the config of `@App`. Defaults
* to `false`.
* @return {boolean}
*/
isProd(): boolean {
return this._isProd;
}
/**
* @private
*/
setProd(val: boolean) {
this._isProd = !!val;
}
/** /**
* @private * @private
* Sets if the app is currently enabled or not, meaning if it's * Sets if the app is currently enabled or not, meaning if it's
@ -97,7 +107,7 @@ export class IonicApp {
* @param {object} component The component to register * @param {object} component The component to register
*/ */
register(id: string, component: any) { register(id: string, component: any) {
this.components[id] = component; this._cmps[id] = component;
} }
/** /**
@ -106,7 +116,7 @@ export class IonicApp {
* @param {string} id The id to use to unregister * @param {string} id The id to use to unregister
*/ */
unregister(id: string) { unregister(id: string) {
delete this.components[id]; delete this._cmps[id];
} }
/** /**
@ -116,8 +126,8 @@ export class IonicApp {
* @return {object} the matching component, or undefined if none was found * @return {object} the matching component, or undefined if none was found
*/ */
getRegisteredComponent(cls: any): any { getRegisteredComponent(cls: any): any {
for (let key in this.components) { for (let key in this._cmps) {
const component = this.components[key]; const component = this._cmps[key];
if (component instanceof cls) { if (component instanceof cls) {
return component; return component;
} }
@ -127,8 +137,6 @@ export class IonicApp {
/** /**
* @private * @private
* Get the component for the given key. * Get the component for the given key.
* @param {string} id TODO
* @return {object} TODO
*/ */
getComponent(id: string): any { getComponent(id: string): any {
// deprecated warning // deprecated warning
@ -147,7 +155,7 @@ export class IonicApp {
); );
} }
return this.components[id]; return this._cmps[id];
} }
} }

View File

@ -1,4 +1,4 @@
import {App, Page, Animation} from '../../../../../ionic/ionic'; import {App, Page, Animation, IonicApp} from '../../../../../ionic/ionic';
@Page({ @Page({
@ -8,9 +8,11 @@ class E2EPage {
duration; duration;
easing; easing;
constructor() { constructor(app: IonicApp) {
this.duration = '1000'; this.duration = '1000';
this.easing = 'ease-in-out'; this.easing = 'ease-in-out';
console.log('isProd', app.isProd());
} }
playGreen() { playGreen() {
@ -24,7 +26,8 @@ class E2EPage {
@App({ @App({
template: '<ion-nav [root]="root"></ion-nav>' template: '<ion-nav [root]="root"></ion-nav>',
prodMode: true
}) })
class E2EApp { class E2EApp {
root; root;

View File

@ -1,5 +1,6 @@
import {Component, ChangeDetectionStrategy, ViewEncapsulation, enableProdMode, Type} from 'angular2/core'; import {Component, ChangeDetectionStrategy, ViewEncapsulation, enableProdMode, Type} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser'; import {bootstrap} from 'angular2/platform/browser';
import {IonicApp} from '../components/app/app';
import {TapClick} from '../components/tap-click/tap-click'; import {TapClick} from '../components/tap-click/tap-click';
import {ionicProviders} from '../config/bootstrap'; import {ionicProviders} from '../config/bootstrap';
import {IONIC_DIRECTIVES} from '../config/directives'; import {IONIC_DIRECTIVES} from '../config/directives';
@ -57,7 +58,7 @@ export interface AppMetadata {
* ``` * ```
* *
* @property {object} [config] - the app's {@link /docs/v2/api/config/Config/ Config} object. * @property {object} [config] - the app's {@link /docs/v2/api/config/Config/ Config} object.
* @property {boolean} [prodMode] - Enable Angular's production mode, which turns off assertions and other checks within the framework. Defaults to `false`. * @property {boolean} [prodMode] - Enable Angular's production mode, which turns off assertions and other checks within the framework. Additionally, this config sets the return value of `isProd()` which is on the `IonicApp` instance. Defaults to `false`.
* @property {array} [pipes] - any pipes for your app. * @property {array} [pipes] - any pipes for your app.
* @property {array} [providers] - any providers for your app. * @property {array} [providers] - any providers for your app.
* @property {string} [template] - the template to use for the app root. * @property {string} [template] - the template to use for the app root.
@ -94,6 +95,8 @@ export function App(args: AppMetadata={}) {
bootstrap(cls, providers).then(appRef => { bootstrap(cls, providers).then(appRef => {
appRef.injector.get(TapClick); appRef.injector.get(TapClick);
let app: IonicApp = appRef.injector.get(IonicApp);
app.setProd(args.prodMode);
}); });
return cls; return cls;