From 6b2f42467ffc6b1e1e2f7c99d05b13d67bda34e4 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 15 Jan 2016 11:03:14 -0600 Subject: [PATCH] fix(navParams): move navParams to nav-params.ts --- ionic/components/action-sheet/action-sheet.ts | 6 +- ionic/components/alert/alert.ts | 6 +- ionic/components/nav/nav-controller.ts | 89 ++++--------------- ionic/components/nav/nav-params.ts | 54 +++++++++++ ionic/components/nav/nav-router.ts | 2 +- .../nav/test/nav-controller.spec.ts | 9 ++ ionic/components/nav/view-controller.ts | 5 +- 7 files changed, 93 insertions(+), 78 deletions(-) create mode 100644 ionic/components/nav/nav-params.ts diff --git a/ionic/components/action-sheet/action-sheet.ts b/ionic/components/action-sheet/action-sheet.ts index fce0a5e7b2..07cac4059d 100644 --- a/ionic/components/action-sheet/action-sheet.ts +++ b/ionic/components/action-sheet/action-sheet.ts @@ -1,11 +1,11 @@ import {Component, Renderer, ElementRef} from 'angular2/core'; import {NgFor, NgIf} from 'angular2/common'; -import {NavParams} from '../nav/nav-controller'; -import {ViewController} from '../nav/view-controller'; +import {Animation} from '../../animations/animation'; import {Config} from '../../config/config'; import {Icon} from '../icon/icon'; -import {Animation} from '../../animations/animation'; +import {NavParams} from '../nav/nav-params'; +import {ViewController} from '../nav/view-controller'; /** diff --git a/ionic/components/alert/alert.ts b/ionic/components/alert/alert.ts index d5950adda1..8049121b2c 100644 --- a/ionic/components/alert/alert.ts +++ b/ionic/components/alert/alert.ts @@ -1,11 +1,11 @@ import {Component, ElementRef, Renderer} from 'angular2/core'; import {NgClass, NgSwitch, NgIf, NgFor} from 'angular2/common'; -import {NavParams} from '../nav/nav-controller'; -import {ViewController} from '../nav/view-controller'; -import {Config} from '../../config/config'; import {Animation} from '../../animations/animation'; +import {Config} from '../../config/config'; import {isDefined} from '../../util/util'; +import {NavParams} from '../nav/nav-params'; +import {ViewController} from '../nav/view-controller'; /** diff --git a/ionic/components/nav/nav-controller.ts b/ionic/components/nav/nav-controller.ts index 76e8deb477..badb8aafbb 100644 --- a/ionic/components/nav/nav-controller.ts +++ b/ionic/components/nav/nav-controller.ts @@ -1,15 +1,16 @@ import {Compiler, ElementRef, Injector, provide, NgZone, AppViewManager, Renderer, ResolvedProvider, Type} from 'angular2/core'; import {wtfLeave, wtfCreateScope, WtfScopeFn, wtfStartTimeRange, wtfEndTimeRange} from 'angular2/instrumentation'; +import {Animation} from '../../animations/animation'; +import {Config} from '../../config/config'; import {Ion} from '../ion'; import {IonicApp} from '../app/app'; -import {Config} from '../../config/config'; -import {Keyboard} from '../../util/keyboard'; -import {ViewController} from './view-controller'; -import {Animation} from '../../animations/animation'; -import {SwipeBackGesture} from './swipe-back'; import {isBoolean, array, pascalCaseToDashCase} from '../../util/util'; +import {Keyboard} from '../../util/keyboard'; +import {NavParams} from './nav-params'; import {raf, rafFrames} from '../../util/dom'; +import {SwipeBackGesture} from './swipe-back'; +import {ViewController} from './view-controller'; /** * _For examples on the basic usage of NavController, check out the @@ -1496,70 +1497,18 @@ export class NavController extends Ion { } -const STATE_ACTIVE = 1; -const STATE_INACTIVE = 2; -const STATE_INIT_ENTER = 3; -const STATE_INIT_LEAVE = 4; -const STATE_RENDER_ENTER = 5; -const STATE_RENDER_LEAVE = 6; -const STATE_POST_RENDER_ENTER = 7; -const STATE_POST_RENDER_LEAVE = 8; -const STATE_BEFORE_TRANS_ENTER = 9; -const STATE_BEFORE_TRANS_LEAVE = 10; -const STATE_AFTER_TRANS_ENTER = 11; -const STATE_AFTER_TRANS_LEAVE = 12; +export const STATE_ABORT = -1; +export const STATE_ACTIVE = 1; +export const STATE_INACTIVE = 2; +export const STATE_INIT_ENTER = 3; +export const STATE_INIT_LEAVE = 4; +export const STATE_RENDER_ENTER = 5; +export const STATE_RENDER_LEAVE = 6; +export const STATE_POST_RENDER_ENTER = 7; +export const STATE_POST_RENDER_LEAVE = 8; +export const STATE_BEFORE_TRANS_ENTER = 9; +export const STATE_BEFORE_TRANS_LEAVE = 10; +export const STATE_AFTER_TRANS_ENTER = 11; +export const STATE_AFTER_TRANS_LEAVE = 12; let ctrlIds = -1; - - -/** - * @name NavParams - * @description - * NavParams are an object that exists on a page and can contain data for that particular view. - * Similar to how data was pass to a view in V1 with `$stateParams`, NavParams offer a much more flexible - * option with a simple `get` method. - * - * @usage - * ```ts - * export class MyClass{ - * constructor(params: NavParams){ - * this.params = params; - * // userParams is an object we have in our nav-parameters - * this.params.get('userParams'); - * } - * } - * ``` - * @demo /docs/v2/demos/nav-params/ - * @see {@link /docs/v2/components#navigation Navigation Component Docs} - * @see {@link ../NavController/ NavController API Docs} - * @see {@link ../Nav/ Nav API Docs} - * @see {@link ../NavPush/ NavPush API Docs} - */ -export class NavParams { - - /** - * @private - * @param {TODO} data TODO - */ - constructor(public data: any = {}) {} - - /** - * Get the value of a nav-parameter for the current view - * - * ```ts - * export class MyClass{ - * constructor(params: NavParams){ - * this.params = params; - * // userParams is an object we have in our nav-parameters - * this.params.get('userParams'); - * } - * } - * ``` - * - * - * @param {string} parameter Which param you want to look up - */ - get(param: string): any { - return this.data[param]; - } -} diff --git a/ionic/components/nav/nav-params.ts b/ionic/components/nav/nav-params.ts new file mode 100644 index 0000000000..40580c0434 --- /dev/null +++ b/ionic/components/nav/nav-params.ts @@ -0,0 +1,54 @@ + + + +/** + * @name NavParams + * @description + * NavParams are an object that exists on a page and can contain data for that particular view. + * Similar to how data was pass to a view in V1 with `$stateParams`, NavParams offer a much more flexible + * option with a simple `get` method. + * + * @usage + * ```ts + * export class MyClass{ + * constructor(params: NavParams){ + * this.params = params; + * // userParams is an object we have in our nav-parameters + * this.params.get('userParams'); + * } + * } + * ``` + * @demo /docs/v2/demos/nav-params/ + * @see {@link /docs/v2/components#navigation Navigation Component Docs} + * @see {@link ../NavController/ NavController API Docs} + * @see {@link ../Nav/ Nav API Docs} + * @see {@link ../NavPush/ NavPush API Docs} + */ +export class NavParams { + + /** + * @private + * @param {TODO} data TODO + */ + constructor(public data: any = {}) {} + + /** + * Get the value of a nav-parameter for the current view + * + * ```ts + * export class MyClass{ + * constructor(params: NavParams){ + * this.params = params; + * // userParams is an object we have in our nav-parameters + * this.params.get('userParams'); + * } + * } + * ``` + * + * + * @param {string} parameter Which param you want to look up + */ + get(param: string): any { + return this.data[param]; + } +} \ No newline at end of file diff --git a/ionic/components/nav/nav-router.ts b/ionic/components/nav/nav-router.ts index 4db3590c15..1897b4412f 100644 --- a/ionic/components/nav/nav-router.ts +++ b/ionic/components/nav/nav-router.ts @@ -45,7 +45,7 @@ export class NavRouter extends RouterOutlet { // prevent double navigations to the same view var lastView = this._nav.last(); - if (this._nav.isTransitioning() || lastView && lastView.componentType === componentType && lastView.params.data === nextInstruction.params) { + if (this._nav.isTransitioning() || lastView && lastView.componentType === componentType && lastView.data === nextInstruction.params) { return Promise.resolve(); } diff --git a/ionic/components/nav/test/nav-controller.spec.ts b/ionic/components/nav/test/nav-controller.spec.ts index 4fc04b4e9e..a1ac8f11aa 100644 --- a/ionic/components/nav/test/nav-controller.spec.ts +++ b/ionic/components/nav/test/nav-controller.spec.ts @@ -199,6 +199,15 @@ export function run() { expect(nav._views[5].componentType).toBe(FirstPage); }); + it('another insert happened before last insert rendered, abort previous insert enter', () => { + let view1 = new ViewController(); + view1._loaded = true; + view1.state = NavController.STATE_ABORT; + let view2 = new ViewController(); + view2._loaded = true; + nav._views = [view1, view2]; + }); + }); describe("setRoot", () => { diff --git a/ionic/components/nav/view-controller.ts b/ionic/components/nav/view-controller.ts index 985fc8d04b..e9d8042af4 100644 --- a/ionic/components/nav/view-controller.ts +++ b/ionic/components/nav/view-controller.ts @@ -1,6 +1,9 @@ import {Output, EventEmitter, Type, TemplateRef, ViewContainerRef, ElementRef} from 'angular2/core'; -import {NavController, NavParams} from './nav-controller'; + import {Navbar} from '../navbar/navbar'; +import {NavController} from './nav-controller'; +import {NavParams} from './nav-params'; + /** * @name ViewController