Skip to content

Commit

Permalink
perf(compose): check if it is a instance only once
Browse files Browse the repository at this point in the history
  • Loading branch information
EdamAme-x committed Oct 30, 2024
1 parent 3164326 commit b0ee588
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const compose = <C extends ComposeContext, E extends Env = Env>(
): ((context: C, next?: Function) => Promise<C>) => {
return (context, next) => {
let index = -1
const isContext = context instanceof Context

return dispatch(0)

/**
Expand All @@ -58,15 +60,13 @@ export const compose = <C extends ComposeContext, E extends Env = Env>(

if (middleware[i]) {
handler = middleware[i][0][0]
if (context instanceof Context) {
context.req.routeIndex = i
}
if (isContext) context.req.routeIndex = i

Check failure on line 63 in src/compose.ts

View workflow job for this annotation

GitHub Actions / Main

Expected { after 'if' condition
} else {
handler = (i === middleware.length && next) || undefined
}

if (!handler) {
if (context instanceof Context && context.finalized === false && onNotFound) {
if (context.finalized === false && isContext && onNotFound) {
res = await onNotFound(context)
}
} else {
Expand All @@ -75,7 +75,7 @@ export const compose = <C extends ComposeContext, E extends Env = Env>(
return dispatch(i + 1)
})
} catch (err) {
if (err instanceof Error && context instanceof Context && onError) {
if (err instanceof Error && isContext && onError) {
context.error = err
res = await onError(err, context)
isError = true
Expand Down

0 comments on commit b0ee588

Please sign in to comment.