fix(navCtrl): wrap user lifecycle evts w/ try/catch

This commit is contained in:
Adam Bradley
2015-11-28 00:10:38 -06:00
parent 1d1f94cab6
commit ad276f4161
4 changed files with 34 additions and 20 deletions

View File

@@ -699,24 +699,18 @@ export class NavController extends Ion {
return done();
}
function loaded() {
// this ViewController instance has finished loading
try {
viewCtrl.loaded();
} catch (e) {
console.error(e);
}
done();
}
// get the pane the NavController wants to use
// the pane is where all this content will be placed into
this.loadPage(viewCtrl, null, () => {
if (viewCtrl.onReady) {
viewCtrl.onReady(loaded);
viewCtrl.onReady(() => {
viewCtrl.loaded();
done();
});
} else {
loaded();
viewCtrl.loaded();
done();
}
});

View File

@@ -63,6 +63,12 @@ class FirstPage {
}
}
onPageLoaded() {
console.log('onPageLoaded');
var meNoWorky = true;
meNoWorky(helloIsItMeYoureLookingFor);
}
setPages() {
let items = [
PrimaryHeaderPage

View File

@@ -157,7 +157,7 @@ export class ViewController {
loaded() {
this._loaded = true;
if (!this.shouldDestroy) {
this.instance.onPageLoaded && this.instance.onPageLoaded();
ctrlFn(this, 'onPageLoaded');
}
}
@@ -166,7 +166,7 @@ export class ViewController {
*/
willEnter() {
if (!this.shouldDestroy) {
this.instance.onPageWillEnter && this.instance.onPageWillEnter();
ctrlFn(this, 'onPageWillEnter');
}
}
@@ -177,14 +177,14 @@ export class ViewController {
didEnter() {
let navbar = this.getNavbar();
navbar && navbar.didEnter();
this.instance.onPageDidEnter && this.instance.onPageDidEnter();
ctrlFn(this, 'onPageDidEnter');
}
/**
* The view has is about to leave and no longer be the active view.
*/
willLeave() {
this.instance.onPageWillLeave && this.instance.onPageWillLeave();
ctrlFn(this, 'onPageWillLeave');
}
/**
@@ -192,21 +192,31 @@ export class ViewController {
* will fire, whether it is cached or unloaded.
*/
didLeave() {
this.instance.onPageDidLeave && this.instance.onPageDidLeave();
ctrlFn(this, 'onPageDidLeave');
}
/**
* The view is about to be destroyed and have its elements removed.
*/
willUnload() {
this.instance.onPageWillUnload && this.instance.onPageWillUnload();
ctrlFn(this, 'onPageWillUnload');
}
/**
* The view has been destroyed and its elements have been removed.
*/
didUnload() {
this.instance.onPageDidUnload && this.instance.onPageDidUnload();
ctrlFn(this, 'onPageDidUnload');
}
}
function ctrlFn(viewCtrl, fnName) {
if (viewCtrl.instance && viewCtrl.instance[fnName]) {
try {
viewCtrl.instance[fnName]();
} catch(e) {
console.error(fnName + ': ' + e.message);
}
}
}

View File

@@ -172,7 +172,11 @@ export class Navbar extends ToolbarBase {
* @private
*/
didEnter() {
this.app.setTitle(this.getTitleText());
try {
this.app.setTitle(this.getTitleText());
} catch(e) {
console.error(e);
}
}
/**