Skip to content

Commit 50a675a

Browse files
committed
chore: remove functional functions
1 parent c5d77ae commit 50a675a

File tree

1 file changed

+12
-14
lines changed
  • packages/router/src/navigation-api

1 file changed

+12
-14
lines changed

packages/router/src/navigation-api/index.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
9090
function checkCanceledNavigation(
9191
to: RouteLocationNormalized,
9292
from: RouteLocationNormalized
93-
): NavigationFailure | void {
93+
): NavigationFailure | undefined {
9494
if (pendingLocation !== to) {
9595
return createRouterError<NavigationFailure>(
9696
ErrorTypes.NAVIGATION_CANCELLED,
@@ -100,14 +100,16 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
100100
}
101101
)
102102
}
103+
104+
return undefined
103105
}
104106

105107
function checkCanceledNavigationAndReject(
106108
to: RouteLocationNormalized,
107109
from: RouteLocationNormalized
108-
): Promise<void> {
110+
) {
109111
const error = checkCanceledNavigation(to, from)
110-
return error ? Promise.reject(error) : Promise.resolve()
112+
if (error) throw error
111113
}
112114

113115
function runWithContext<T>(fn: () => T): T {
@@ -118,11 +120,10 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
118120
: fn()
119121
}
120122

121-
function runGuardQueue(guards: Lazy<any>[]): Promise<any> {
122-
return guards.reduce(
123-
(promise, guard) => promise.then(() => runWithContext(guard)),
124-
Promise.resolve()
125-
)
123+
async function runGuardQueue(guards: Lazy<any>[]): Promise<any> {
124+
for (const guard of guards) {
125+
await runWithContext(guard)
126+
}
126127
}
127128

128129
let ready: boolean = false
@@ -146,14 +147,11 @@ export function createNavigationApiRouter(options: RouterApiOptions): Router {
146147
navigationInfo
147148
)
148149

149-
const canceledNavigationCheck = checkCanceledNavigationAndReject.bind(
150-
null,
151-
to,
152-
from
153-
)
150+
const canceledNavigationCheck = async () => {
151+
checkCanceledNavigationAndReject(to, from)
152+
}
154153

155154
guards.push(canceledNavigationCheck)
156-
157155
await runGuardQueue(guards)
158156

159157
// check global guards beforeEach

0 commit comments

Comments
 (0)