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

refactor(jsx): shorten use hook a bit (#2231)

* refactor(jsx): shorten use hook a bit

* chore: denoify
This commit is contained in:
Taku Amano 2024-02-17 16:40:35 +09:00 committed by GitHub
parent e49c140c62
commit 7cf7432216
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 16 deletions

View File

@ -274,9 +274,10 @@ export const use = <T>(promise: Promise<T>): T => {
}
return cachedRes[0] as T
}
promise
.then((res) => resolvedPromiseValueMap.set(promise, [res]))
.catch((e) => resolvedPromiseValueMap.set(promise, [undefined, e]))
promise.then(
(res) => resolvedPromiseValueMap.set(promise, [res]),
(e) => resolvedPromiseValueMap.set(promise, [undefined, e])
)
const buildData = buildDataStack.at(-1) as [unknown, NodeObject]
if (!buildData) {
@ -287,13 +288,14 @@ export const use = <T>(promise: Promise<T>): T => {
const promiseArray = (node[DOM_STASH][1][STASH_USE] ||= [])
const hookIndex = node[DOM_STASH][0]++
promise
.then((res) => {
promise.then(
(res) => {
promiseArray[hookIndex] = [res]
})
.catch((e) => {
},
(e) => {
promiseArray[hookIndex] = [undefined, e]
})
}
)
const res = promiseArray[hookIndex]
if (res) {

View File

@ -274,9 +274,10 @@ export const use = <T>(promise: Promise<T>): T => {
}
return cachedRes[0] as T
}
promise
.then((res) => resolvedPromiseValueMap.set(promise, [res]))
.catch((e) => resolvedPromiseValueMap.set(promise, [undefined, e]))
promise.then(
(res) => resolvedPromiseValueMap.set(promise, [res]),
(e) => resolvedPromiseValueMap.set(promise, [undefined, e])
)
const buildData = buildDataStack.at(-1) as [unknown, NodeObject]
if (!buildData) {
@ -287,13 +288,14 @@ export const use = <T>(promise: Promise<T>): T => {
const promiseArray = (node[DOM_STASH][1][STASH_USE] ||= [])
const hookIndex = node[DOM_STASH][0]++
promise
.then((res) => {
promise.then(
(res) => {
promiseArray[hookIndex] = [res]
})
.catch((e) => {
},
(e) => {
promiseArray[hookIndex] = [undefined, e]
})
}
)
const res = promiseArray[hookIndex]
if (res) {