0
0
mirror of https://github.com/honojs/hono.git synced 2024-12-01 11:51:01 +01:00

refactor(compose): cache length (#460)

This commit is contained in:
Yusuke Wada 2022-08-09 10:28:04 +09:00 committed by GitHub
parent 6d306b8218
commit 0370cac372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ export const compose = <C>(
onError?: ErrorHandler,
onNotFound?: NotFoundHandler
) => {
const middlewareLength = middleware.length
return (context: C, next?: Function) => {
let index = -1
return dispatch(0)
@ -16,7 +17,7 @@ export const compose = <C>(
}
let handler = middleware[i]
index = i
if (i === middleware.length && next) handler = next
if (i === middlewareLength && next) handler = next
if (!handler) {
if (context instanceof HonoContext && context.finalized === false && onNotFound) {