diff --git a/ionic/components/app/app.ts b/ionic/components/app/app.ts index e5c612c21c..7cc560f67b 100644 --- a/ionic/components/app/app.ts +++ b/ionic/components/app/app.ts @@ -13,13 +13,12 @@ import {rafFrames} from '../../util/dom'; */ @Injectable() export class IonicApp { - private _titleSrv: Title = new Title(); - private _title: string = ''; + private _cmps: {[id: string] : any} = {}; private _disTime: number = 0; private _scrollTime: number = 0; - - // Our component registry map - private components: {[id: string] : any} = {}; + private _title: string = ''; + private _titleSrv: Title = new Title(); + private _isProd: boolean = false; constructor( private _config: Config, @@ -32,18 +31,29 @@ export class IonicApp { * @param {string} val Value to set the document title to. */ setTitle(val: string) { - let self = this; - if (val !== self._title) { - self._title = val; - this._zone.runOutsideAngular(() => { - function setAppTitle() { - self._titleSrv.setTitle(self._title); - } - rafFrames(4, setAppTitle); - }); + if (val !== this._title) { + this._title = val; + this._titleSrv.setTitle(val); } } + /** + * 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 * 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 */ 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 */ 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 */ getRegisteredComponent(cls: any): any { - for (let key in this.components) { - const component = this.components[key]; + for (let key in this._cmps) { + const component = this._cmps[key]; if (component instanceof cls) { return component; } @@ -127,8 +137,6 @@ export class IonicApp { /** * @private * Get the component for the given key. - * @param {string} id TODO - * @return {object} TODO */ getComponent(id: string): any { // deprecated warning @@ -147,7 +155,7 @@ export class IonicApp { ); } - return this.components[id]; + return this._cmps[id]; } } diff --git a/ionic/components/app/test/animations/index.ts b/ionic/components/app/test/animations/index.ts index 9f29879bcb..d2b532b74f 100644 --- a/ionic/components/app/test/animations/index.ts +++ b/ionic/components/app/test/animations/index.ts @@ -1,4 +1,4 @@ -import {App, Page, Animation} from '../../../../../ionic/ionic'; +import {App, Page, Animation, IonicApp} from '../../../../../ionic/ionic'; @Page({ @@ -8,9 +8,11 @@ class E2EPage { duration; easing; - constructor() { + constructor(app: IonicApp) { this.duration = '1000'; this.easing = 'ease-in-out'; + + console.log('isProd', app.isProd()); } playGreen() { @@ -24,7 +26,8 @@ class E2EPage { @App({ - template: '' + template: '', + prodMode: true }) class E2EApp { root; diff --git a/ionic/decorators/app.ts b/ionic/decorators/app.ts index b759a8370b..c16539c14e 100644 --- a/ionic/decorators/app.ts +++ b/ionic/decorators/app.ts @@ -1,5 +1,6 @@ import {Component, ChangeDetectionStrategy, ViewEncapsulation, enableProdMode, Type} from 'angular2/core'; import {bootstrap} from 'angular2/platform/browser'; +import {IonicApp} from '../components/app/app'; import {TapClick} from '../components/tap-click/tap-click'; import {ionicProviders} from '../config/bootstrap'; 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 {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} [providers] - any providers for your app. * @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 => { appRef.injector.get(TapClick); + let app: IonicApp = appRef.injector.get(IonicApp); + app.setProd(args.prodMode); }); return cls;