Skip to content

Commit

Permalink
refactor(): pass through enteringView and stack controller
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-perkins committed Jul 28, 2022
1 parent aae915b commit 0cdd577
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
11 changes: 7 additions & 4 deletions angular/src/directives/navigation/ion-router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

/**
Expand Down
17 changes: 10 additions & 7 deletions angular/src/providers/nav-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<StackEvent>;
stackCtrl: StackController;
enteringView: RouteView;
}>();

// Queue of change events for assigning the top outlet (after the active view has transitioned)
Expand Down Expand Up @@ -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 }))
)
)
)
Expand Down Expand Up @@ -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<StackEvent>): Observable<StackEvent> {
setTopOutlet(outlet: IonRouterOutlet, stackCtrl: StackController, enteringView: RouteView): Observable<StackEvent> {
this.topOutletQueue$.next({
outlet,
setActiveView,
stackCtrl,
enteringView,
});

return this.topOutletChange$.pipe(
Expand Down

0 comments on commit 0cdd577

Please sign in to comment.