0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-21 18:18:57 +01:00

refactor(app): add "deprecate message" for app.handleEvent() (#1298)

* refactor(app): add "deprecate message" for `app.handleEvent()`

* denoify
This commit is contained in:
Yusuke Wada 2023-08-05 23:41:45 +09:00 committed by GitHub
parent 4a3c5834de
commit 85f8ab663f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -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)

View File

@ -351,6 +351,11 @@ class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> 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<E extends Env = Env, S = {}, BasePath extends string = '/'> 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))
})
}
}

View File

@ -351,6 +351,11 @@ class Hono<E extends Env = Env, S = {}, BasePath extends string = '/'> 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<E extends Env = Env, S = {}, BasePath extends string = '/'> 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))
})
}
}