fix(nav): adds public willLoad lifecycle event

* fix(nav): adds public willLoad lifecycle event

* test(menu): adds more asserts
This commit is contained in:
Manu Mtz.-Almeida
2016-11-01 19:12:29 +01:00
committed by Adam Bradley
parent 504e6e0440
commit 033e1eae17
9 changed files with 195 additions and 26 deletions

View File

@ -419,12 +419,15 @@ export class NavControllerBase extends Ion implements NavController {
// create ComponentRef and set it to the entering view
enteringView.init(componentFactory.create(childInjector, []));
enteringView._state = ViewState.INITIALIZED;
this._willLoad(enteringView);
this._preLoad(enteringView);
}
_viewAttachToDOM(view: ViewController, componentRef: ComponentRef<any>, viewport: ViewContainerRef) {
assert(view._state === ViewState.INITIALIZED, 'view state must be INITIALIZED');
// fire willLoad before change detection runs
this._willLoad(view);
// render the component ref instance to the DOM
// ******** DOM WRITE ****************
viewport.insert(componentRef.hostView, viewport.length);
@ -438,14 +441,11 @@ export class NavControllerBase extends Ion implements NavController {
this._renderer.setElementClass(pageElement, view._cssClass, true);
}
// TODO:
// componentRef.changeDetectorRef.detectChanges();
componentRef.changeDetectorRef.detectChanges();
// successfully finished loading the entering view
// fire off the "didLoad" lifecycle events
this._didLoad(view);
componentRef.changeDetectorRef.detectChanges();
}
_viewTest(enteringView: ViewController, leavingView: ViewController, ti: TransitionInstruction) {
@ -753,6 +753,12 @@ export class NavControllerBase extends Ion implements NavController {
}
}
_preLoad(view: ViewController) {
assert(this.isTransitioning(), 'nav controller should be transitioning');
view._preLoad();
}
_willLoad(view: ViewController) {
assert(this.isTransitioning(), 'nav controller should be transitioning');

View File

@ -434,6 +434,15 @@ export class ViewController {
/**
* @private
*/
_preLoad() {
this._lifecycle('PreLoad');
}
/**
* @private
* The view has loaded. This event only happens once per view will be created.
* This event is fired before the component and his children have been initialized.
*/
_willLoad() {
this._lifecycle('WillLoad');
}