Skip to content

Commit dc75392

Browse files
authored
refactor(router-outlet): reuse lock controller (#28273)
Issue number: Internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> Code is duplicated between the router outlet and the overlays ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Code is reused between the router outlet and the overlays ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. -->
1 parent 865bd2a commit dc75392

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

Diff for: core/src/components/router-outlet/router-outlet.tsx

+3-14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Component, Element, Event, Method, Prop, Watch, h } from '@stencil/core
33
import { getTimeGivenProgression } from '@utils/animation/cubic-bezier';
44
import { attachComponent, detachComponent } from '@utils/framework-delegate';
55
import { shallowEqualStringMap, hasLazyBuild } from '@utils/helpers';
6+
import { createLockController } from '@utils/lock-controller';
67
import { transition } from '@utils/transition';
78

89
import { config } from '../../global/config';
@@ -24,11 +25,11 @@ import type { RouteID, RouterDirection, RouteWrite, NavOutlet } from '../router/
2425
shadow: true,
2526
})
2627
export class RouterOutlet implements ComponentInterface, NavOutlet {
28+
private readonly lockController = createLockController();
2729
private activeEl: HTMLElement | undefined;
2830
// TODO(FW-2832): types
2931
private activeComponent: any;
3032
private activeParams: any;
31-
private waitPromise?: Promise<void>;
3233
private gesture?: Gesture;
3334
private ani?: Animation;
3435
private gestureOrAnimationInProgress = false;
@@ -140,7 +141,7 @@ export class RouterOutlet implements ComponentInterface, NavOutlet {
140141
leavingEl: HTMLElement | undefined,
141142
opts?: RouterOutletOptions
142143
): Promise<boolean> {
143-
const unlock = await this.lock();
144+
const unlock = await this.lockController.lock();
144145
let changed = false;
145146
try {
146147
changed = await this.transition(enteringEl, leavingEl, opts);
@@ -285,18 +286,6 @@ export class RouterOutlet implements ComponentInterface, NavOutlet {
285286
return true;
286287
}
287288

288-
// TODO: FW-5048 - Remove this code in favor of using lock controller from utils
289-
private async lock() {
290-
const p = this.waitPromise;
291-
let resolve!: () => void;
292-
this.waitPromise = new Promise((r) => (resolve = r));
293-
294-
if (p !== undefined) {
295-
await p;
296-
}
297-
return resolve;
298-
}
299-
300289
render() {
301290
return <slot></slot>;
302291
}

0 commit comments

Comments
 (0)