From 85f8ab663f9a5e72bab68d2e4b0849c59982f602 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Sat, 5 Aug 2023 23:41:45 +0900 Subject: [PATCH] refactor(app): add "deprecate message" for `app.handleEvent()` (#1298) * refactor(app): add "deprecate message" for `app.handleEvent()` * denoify --- benchmarks/handle-event/index.js | 4 ++-- deno_dist/hono-base.ts | 9 +++++++-- src/hono-base.ts | 9 +++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/benchmarks/handle-event/index.js b/benchmarks/handle-event/index.js index bb417885..772efe46 100644 --- a/benchmarks/handle-event/index.js +++ b/benchmarks/handle-event/index.js @@ -114,7 +114,7 @@ makeEdgeEnv() const event = new FetchEvent('fetch', { request }) const fn = async () => { - let res = await hono.handleEvent(event) + let res = await hono.fetch(event.request) console.log(await res.text()) res = await ittyRouter.handle(event.request) console.log(await res.text()) @@ -129,7 +129,7 @@ const suite = new Benchmark.Suite() suite .add('Hono', async () => { - await hono.handleEvent(event) + await hono.fetch(event.request) }) .add('itty-router', async () => { await ittyRouter.handle(event.request) diff --git a/deno_dist/hono-base.ts b/deno_dist/hono-base.ts index 5965ab41..2ed34f89 100644 --- a/deno_dist/hono-base.ts +++ b/deno_dist/hono-base.ts @@ -351,6 +351,11 @@ class Hono extends d })() } + /** + * @deprecate + * `app.handleEvent()` will be removed in v4. + * Use `app.fetch()` instead of `app.handleEvent()`. + */ handleEvent = (event: FetchEventLike) => { return this.dispatch(event.request, event, undefined, event.request.method) } @@ -375,8 +380,8 @@ class Hono extends d fire = () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - addEventListener('fetch', (event: FetchEvent): void => { - void event.respondWith(this.handleEvent(event)) + addEventListener('fetch', (event: FetchEventLike): void => { + event.respondWith(this.dispatch(event.request, event, undefined, event.request.method)) }) } } diff --git a/src/hono-base.ts b/src/hono-base.ts index 882943d9..378f5846 100644 --- a/src/hono-base.ts +++ b/src/hono-base.ts @@ -351,6 +351,11 @@ class Hono extends d })() } + /** + * @deprecate + * `app.handleEvent()` will be removed in v4. + * Use `app.fetch()` instead of `app.handleEvent()`. + */ handleEvent = (event: FetchEventLike) => { return this.dispatch(event.request, event, undefined, event.request.method) } @@ -375,8 +380,8 @@ class Hono extends d fire = () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - addEventListener('fetch', (event: FetchEvent): void => { - void event.respondWith(this.handleEvent(event)) + addEventListener('fetch', (event: FetchEventLike): void => { + event.respondWith(this.dispatch(event.request, event, undefined, event.request.method)) }) } }