Skip to content

Commit

Permalink
fix(useFetch): chain callbacks should be executed in order
Browse files Browse the repository at this point in the history
  • Loading branch information
younggglcy committed Sep 20, 2022
1 parent 402dce5 commit 553d9b4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/core/useFetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ function headersToObject(headers: HeadersInit | undefined) {

function chainCallbacks<T = any>(...callbacks: (((ctx: T) => void | Partial<T> | Promise<void | Partial<T>>) | undefined)[]) {
return async (ctx: T) => {
await Promise.all(callbacks.map(async (callback) => {
await callbacks.reduce(async (prevCallback, callback) => {
await prevCallback
if (callback)
ctx = { ...ctx, ...(await callback(ctx)) }
}))
}, Promise.resolve())
return ctx
}
}
Expand Down

0 comments on commit 553d9b4

Please sign in to comment.