refactor(external-router): remove the external router controller, move the reconciliation methods to the nav itself, and move the external activation status information to ion-app

This commit is contained in:
Dan Bucholtz
2018-02-15 23:14:09 -06:00
parent 902c4c7f72
commit 3f6e1ddbcd
13 changed files with 213 additions and 217 deletions

View File

@ -28,7 +28,7 @@ import { OutletInjector } from './outlet-injector';
import { RouteEventHandler } from './route-event-handler';
import { AngularComponentMounter, AngularEscapeHatch } from '..';
import { ensureExternalRounterController } from '../util/util';
import { getIonApp } from '../util/util';
let id = 0;
@ -139,9 +139,14 @@ export class RouterOutlet implements OnDestroy, OnInit, RouterDelegate {
export function activateRoute(navElement: HTMLIonNavElement,
component: Type<any>, data: any = {}, cfr: ComponentFactoryResolver, injector: Injector, isTopLevel: boolean): Promise<void> {
return ensureExternalRounterController().then((externalRouterController) => {
return getIonApp().then((ionApp) => {
if (!ionApp) {
return Promise.reject(new Error(`<ion-app> element is required for angular router integration`));
}
const escapeHatch = getEscapeHatch(cfr, injector);
return externalRouterController.reconcileNav(navElement, component, data, escapeHatch, isTopLevel);
return navElement.componentOnReady().then(() => {
return navElement.reconcileFromExternalRouter(component, data, escapeHatch, isTopLevel);
});
});
}

View File

@ -5,7 +5,7 @@ import {
Router
} from '@angular/router';
import { ensureExternalRounterController } from '../util/util';
import { getIonApp } from '../util/util';
@Injectable()
export class RouteEventHandler {
@ -14,16 +14,16 @@ export class RouteEventHandler {
router.events.subscribe((event: Event) => {
if (event instanceof NavigationEnd) {
ensureExternalRounterController().then((element) => {
element.updateExternalNavOccuring(false);
getIonApp().then((appElement) => {
appElement.updateExternalNavOccuring(false);
});
}
});
}
externalNavStart() {
return ensureExternalRounterController().then((element) => {
element.updateExternalNavOccuring(true);
return getIonApp().then((appElement) => {
appElement.updateExternalNavOccuring(true);
});
}
}

View File

@ -26,12 +26,7 @@ export function isString(something: any) {
return typeof something === 'string' ? true : false;
}
export function ensureExternalRounterController(): Promise<HTMLIonExternalRouterControllerElement> {
const element = document.querySelector('ion-external-router-controller');
if (element) {
return (element as any).componentOnReady();
}
const toCreate = document.createElement('ion-external-router-controller');
document.body.appendChild(toCreate);
return (toCreate as any).componentOnReady();
export function getIonApp(): Promise<HTMLIonAppElement> {
const element = ensureElementInBody('ion-app') as HTMLIonAppElement;
return element.componentOnReady();
}