-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(intercrptors): 修改了queue和wrapperHook的返回值以支持异步resolve(false)) #5819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,9 @@ export const scopedInterceptors: { [key: string]: Interceptors } = {} | |
|
||
function wrapperHook(hook: Function, params?: Record<string, any>) { | ||
return function (data: unknown) { | ||
return hook(data, params) || data | ||
const result = hook(data, params); | ||
// 只有当结果为undefined或null时才返回data,保留false值 | ||
return result === undefined || result === null ? data : result; | ||
} | ||
} | ||
|
||
|
@@ -35,12 +37,33 @@ function queue( | |
for (let i = 0; i < hooks.length; i++) { | ||
const hook = hooks[i] | ||
if (promise) { | ||
promise = Promise.resolve(wrapperHook(hook, params)) | ||
const wrappedHook = wrapperHook(hook, params); | ||
promise = promise.then((data) => { | ||
const res = wrappedHook(data); | ||
if (isPromise(res)) { | ||
return res.then((res) => { | ||
if (res === false) { | ||
return { then() {}, catch() {} } as Promise<undefined>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mock Promise object with empty Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
} | ||
return res; | ||
}); | ||
} | ||
if (res === false) { | ||
return { then() {}, catch() {} } as Promise<undefined>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mock Promise object with empty Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
} | ||
return res; | ||
}); | ||
} else { | ||
const res = hook(data, params) | ||
if (isPromise(res)) { | ||
promise = Promise.resolve(res) | ||
} | ||
// 修改这里:处理异步返回 false 的情况 | ||
promise = res.then((res) => { | ||
if (res === false) { | ||
return { then() {}, catch() {} } as Promise<undefined>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mock Promise object with empty Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
} | ||
return res; | ||
}); | ||
} | ||
if (res === false) { | ||
return { | ||
then() {}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic change from
|| data
to explicit undefined/null checking is significant and may affect other use cases. Consider adding unit tests to verify this doesn't break existing functionality where hooks return other falsy values like 0 or empty string.Copilot uses AI. Check for mistakes.