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:
parent
e49c140c62
commit
7cf7432216
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user