From efd3d04c56de253250eeff8ec72150f0ccd59ac6 Mon Sep 17 00:00:00 2001 From: EdamAmex <121654029+EdamAme-x@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:29:09 +0900 Subject: [PATCH] perf(compose): check if it is a instance only once (#3585) * perf(compose): check if it is a instance only once * chore: fix syntax * chore: sort if condition --- src/compose.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/compose.ts b/src/compose.ts index 83ae97b3..a4e1481c 100644 --- a/src/compose.ts +++ b/src/compose.ts @@ -37,6 +37,8 @@ export const compose = ( ): ((context: C, next?: Function) => Promise) => { return (context, next) => { let index = -1 + const isContext = context instanceof Context + return dispatch(0) /** @@ -58,7 +60,7 @@ export const compose = ( if (middleware[i]) { handler = middleware[i][0][0] - if (context instanceof Context) { + if (isContext) { context.req.routeIndex = i } } else { @@ -66,7 +68,7 @@ export const compose = ( } if (!handler) { - if (context instanceof Context && context.finalized === false && onNotFound) { + if (isContext && context.finalized === false && onNotFound) { res = await onNotFound(context) } } else { @@ -75,7 +77,7 @@ export const compose = ( 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