Skip to content

Commit

Permalink
feat(prodMode): set isProd() when prodMode set in @app config
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Feb 21, 2016
1 parent 5302d63 commit 3c8daa0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
50 changes: 29 additions & 21 deletions ionic/components/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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];
}

/**
Expand All @@ -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;
}
Expand All @@ -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
Expand All @@ -147,7 +155,7 @@ export class IonicApp {
);
}

return this.components[id];
return this._cmps[id];
}

}
9 changes: 6 additions & 3 deletions ionic/components/app/test/animations/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {App, Page, Animation} from '../../../../../ionic/ionic';
import {App, Page, Animation, IonicApp} from '../../../../../ionic/ionic';


@Page({
Expand All @@ -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() {
Expand All @@ -24,7 +26,8 @@ class E2EPage {


@App({
template: '<ion-nav [root]="root"></ion-nav>'
template: '<ion-nav [root]="root"></ion-nav>',
prodMode: true
})
class E2EApp {
root;
Expand Down
5 changes: 4 additions & 1 deletion ionic/decorators/app.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3c8daa0

Please sign in to comment.