From 0cdd577706d271539220867dced1d10c76f9aa49 Mon Sep 17 00:00:00 2001 From: Sean Perkins Date: Thu, 28 Jul 2022 17:16:01 -0400 Subject: [PATCH] refactor(): pass through enteringView and stack controller --- .../directives/navigation/ion-router-outlet.ts | 11 +++++++---- angular/src/providers/nav-controller.ts | 17 ++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/angular/src/directives/navigation/ion-router-outlet.ts b/angular/src/directives/navigation/ion-router-outlet.ts index 9e64f778ac1..e2260ce929e 100644 --- a/angular/src/directives/navigation/ion-router-outlet.ts +++ b/angular/src/directives/navigation/ion-router-outlet.ts @@ -309,10 +309,13 @@ export class IonRouterOutlet implements OnDestroy, OnInit { this.activatedView = enteringView; - this.navCtrl.setTopOutlet(this, this.stackCtrl.setActive(enteringView)).subscribe((stackEvent) => { - this.activateEvents.emit(cmpRef.instance); - this.stackEvents.emit(stackEvent); - }); + this.navCtrl + .setTopOutlet(this, this.stackCtrl, enteringView) + // setTopOutlet() is a take(1) operation so we do not need to manually unsubscribe + .subscribe((stackEvent) => { + this.activateEvents.emit(cmpRef.instance); + this.stackEvents.emit(stackEvent); + }); } /** diff --git a/angular/src/providers/nav-controller.ts b/angular/src/providers/nav-controller.ts index 4ed7ed4c081..6c450389059 100644 --- a/angular/src/providers/nav-controller.ts +++ b/angular/src/providers/nav-controller.ts @@ -6,7 +6,8 @@ import { from, Observable, Subject } from 'rxjs'; import { concatMap, filter, map, take } from 'rxjs/operators'; import { IonRouterOutlet } from '../directives/navigation/ion-router-outlet'; -import { StackEvent } from '../directives/navigation/stack-utils'; +import { StackController } from '../directives/navigation/stack-controller'; +import { RouteView, StackEvent } from '../directives/navigation/stack-utils'; import { Platform } from './platform'; @@ -33,7 +34,8 @@ export class NavController { // The queue of pending tasks to assign the top outlet. private topOutletQueue$ = new Subject<{ outlet: IonRouterOutlet; - setActiveView: Promise; + stackCtrl: StackController; + enteringView: RouteView; }>(); // Queue of change events for assigning the top outlet (after the active view has transitioned) @@ -69,10 +71,10 @@ export class NavController { this.topOutletQueue$ .pipe( // Process the chain of promises for setting the active view (and wait for the transition) - concatMap((ev) => - from(ev.setActiveView).pipe( + concatMap(({ outlet, stackCtrl, enteringView }) => + from(stackCtrl.setActive(enteringView)).pipe( // Remap the data required for the implementation in the router outlet - map((stackEvent) => ({ stackEvent, outlet: ev.outlet })) + map((stackEvent) => ({ stackEvent, outlet })) ) ) ) @@ -205,10 +207,11 @@ export class NavController { * Setting the top outlet is depending on finishing the transition of the previous outlet * leaving the view, before assigning the top outlet. */ - setTopOutlet(outlet: IonRouterOutlet, setActiveView: Promise): Observable { + setTopOutlet(outlet: IonRouterOutlet, stackCtrl: StackController, enteringView: RouteView): Observable { this.topOutletQueue$.next({ outlet, - setActiveView, + stackCtrl, + enteringView, }); return this.topOutletChange$.pipe(