refactor(nav-controller-base): cleanup some logic

NavControllerBase is the core of ionic 2 navigation. It handles all the transitions and it is complicated code to follow.
I am refactoring it to allow future developers and contributors to follow it better.

!node.parent now becomes node.isRoot()

ViewController does not remove itself from the stack, but two new auxiliar function in nav controller: _insertView() and _removeView() are used to add a view to the stack.

And so on...

All e2e and unit tests passing...
This commit is contained in:
Manu Mtz.-Almeida
2016-10-18 16:22:49 +02:00
parent ff1f340285
commit d9e8b1bec6
8 changed files with 173 additions and 162 deletions

View File

@ -528,26 +528,25 @@ export class ViewController {
this._cmp.destroy();
}
if (this._nav) {
// remove it from the nav
const index = this._nav.indexOf(this);
if (index > -1) {
this._nav._views.splice(index, 1);
}
}
this._nav = this._cmp = this.instance = this._cntDir = this._cntRef = this._hdrDir = this._ftrDir = this._nb = this._onWillDismiss = null;
}
/**
* @private
*/
_lifecycleTest(lifecycle: string): boolean | string | Promise<any> {
_lifecycleTest(lifecycle: string): boolean | Promise<any> {
let instance = this.instance;
let methodName = 'ionViewCan' + lifecycle;
if (instance && instance[methodName]) {
try {
return instance[methodName]();
let result = instance[methodName]();
if (result === false) {
return false;
} else if (result instanceof Promise) {
return result;
} else {
return true;
}
} catch (e) {
console.error(`${this.name} ${methodName} error: ${e.message}`);
@ -572,7 +571,6 @@ export class ViewController {
}
export function isViewController(viewCtrl: any) {
return !!(viewCtrl && (<ViewController>viewCtrl)._didLoad && (<ViewController>viewCtrl)._willUnload);
}