Skip to content

Commit

Permalink
fix(useFetch): combineCallbacks does not merge options (#3015)
Browse files Browse the repository at this point in the history
  • Loading branch information
RAX7 committed May 1, 2023
1 parent c110acc commit d051f6f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/core/useFetch/index.ts
Expand Up @@ -230,18 +230,20 @@ function combineCallbacks<T = any>(combination: Combination, ...callbacks: (((ct
// use last callback
return async (ctx: T) => {
const callback = callbacks[callbacks.length - 1]
if (callback !== undefined)
await callback(ctx)
if (callback)
return { ...ctx, ...(await callback(ctx)) }

return ctx
}
}
else {
// chaining and combine result
return async (ctx: T) => {
await callbacks.reduce((prevCallback, callback) => prevCallback.then(async () => {
for (const callback of callbacks) {
if (callback)
ctx = { ...ctx, ...(await callback(ctx)) }
}), Promise.resolve())
}

return ctx
}
}
Expand Down

0 comments on commit d051f6f

Please sign in to comment.