mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
perf(nav): avoid running zone when it is not needed
This commit is contained in:
@ -117,7 +117,7 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
}, done);
|
||||
}
|
||||
|
||||
popAll() {
|
||||
popAll(): Promise<any[]> {
|
||||
let promises: any[] = [];
|
||||
for (var i = this._views.length - 1; i >= 0; i--) {
|
||||
promises.push(this.pop(null));
|
||||
@ -133,6 +133,10 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
}, done);
|
||||
}
|
||||
|
||||
removeView(viewController: ViewController, opts?: NavOptions, done?: Function): Promise<any> {
|
||||
return this.remove(this.indexOf(viewController), 1, opts, done);
|
||||
}
|
||||
|
||||
setRoot(pageOrViewCtrl: any, params?: any, opts?: NavOptions, done?: Function): Promise<any> {
|
||||
let viewControllers = [convertToView(this._linker, pageOrViewCtrl, params)];
|
||||
return this._setPages(viewControllers, opts, done);
|
||||
@ -330,15 +334,16 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
const opts = ti.opts || {};
|
||||
const insertViews = ti.insertViews;
|
||||
const removeStart = ti.removeStart;
|
||||
let view;
|
||||
let destroyQueue: ViewController[] = [];
|
||||
let view: ViewController;
|
||||
let i: number;
|
||||
let destroyQueue: ViewController[];
|
||||
|
||||
// there are views to remove
|
||||
if (isPresent(removeStart)) {
|
||||
assert(removeStart >= 0, 'removeStart can not be negative');
|
||||
assert(ti.removeCount >= 0, 'removeCount can not be negative');
|
||||
|
||||
for (var i = 0; i < ti.removeCount; i++) {
|
||||
destroyQueue = [];
|
||||
for (i = 0; i < ti.removeCount; i++) {
|
||||
view = this._views[i + removeStart];
|
||||
if (view && view !== enteringView && view !== leavingView) {
|
||||
destroyQueue.push(view);
|
||||
@ -356,7 +361,7 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
}
|
||||
|
||||
// add the views to the
|
||||
for (var i = 0; i < insertViews.length; i++) {
|
||||
for (i = 0; i < insertViews.length; i++) {
|
||||
view = insertViews[i];
|
||||
this._insertViewAt(view, ti.insertStart + i);
|
||||
}
|
||||
@ -366,13 +371,16 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
opts.direction = opts.direction || DIRECTION_FORWARD;
|
||||
}
|
||||
}
|
||||
|
||||
// if the views to be removed are in the beginning or middle
|
||||
// and there is not a view that needs to visually transition out
|
||||
// then just destroy them and don't transition anything
|
||||
// batch all of lifecycles together
|
||||
// let's make sure, callbacks are zoned
|
||||
if (destroyQueue && destroyQueue.length > 0) {
|
||||
this._zone.run(() => {
|
||||
for (view of destroyQueue) {
|
||||
for (i = 0; i < destroyQueue.length; i++) {
|
||||
view = destroyQueue[i];
|
||||
this._willLeave(view);
|
||||
this._didLeave(view);
|
||||
this._willUnload(view);
|
||||
@ -380,8 +388,9 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
});
|
||||
|
||||
// once all lifecycle events has been delivered, we can safely detroy the views
|
||||
for (view of destroyQueue) {
|
||||
this._destroyView(view);
|
||||
for (i = 0; i < destroyQueue.length; i++) {
|
||||
this._destroyView(destroyQueue[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (ti.enteringRequiresTransition || ti.leavingRequiresTransition && enteringView !== leavingView) {
|
||||
|
@ -452,6 +452,15 @@ export abstract class NavController {
|
||||
*/
|
||||
abstract remove(startIndex: number, removeCount?: number, opts?: NavOptions, done?: Function): Promise<any>;
|
||||
|
||||
/**
|
||||
* Removes the specified view controller from the nav stack.
|
||||
*
|
||||
* @param {ViewController} [viewController] The viewcontroller to remove.
|
||||
* @param {object} [opts={}] Any options you want to use pass to transtion.
|
||||
* @returns {Promise} Returns a promise which is resolved when the transition has completed.
|
||||
*/
|
||||
abstract removeView(viewController: ViewController, opts?: NavOptions, done?: Function): Promise<any>;
|
||||
|
||||
/**
|
||||
* Set the root for the current navigation stack.
|
||||
* @param {Page|ViewController} page The name of the component you want to push on the navigation stack.
|
||||
|
@ -179,7 +179,7 @@ export class ViewController {
|
||||
|
||||
let options = assign({}, this._leavingOpts, navOptions);
|
||||
this._onWillDismiss && this._onWillDismiss(data, role);
|
||||
return this._nav.remove(this._nav.indexOf(this), 1, options).then(() => {
|
||||
return this._nav.removeView(this, options).then(() => {
|
||||
this._onDidDismiss && this._onDidDismiss(data, role);
|
||||
this._onDidDismiss = null;
|
||||
return data;
|
||||
|
Reference in New Issue
Block a user