Skip to content
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

feat(fetch): add response method. #947

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

feat(fetch): add response method. #947

wants to merge 26 commits into from

Conversation

nianxiongdi
Copy link
Collaborator

No description provided.

@hiyuki
Copy link
Collaborator

hiyuki commented Feb 14, 2022

api实现方式不符合预期

// custom不存在时,进行url参数匹配
const matched = (!test.custom) && doTest(configBackup, test).matched
if (isFunction(callback) && ((isFunction(test.custom) && test.custom(configBackup)) || matched)) {
let data = callback.call(config)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

访问config需要通过this访问吗?建议别这样设计,直接显式传参就尅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是滴,那我修改成显式调用哈

for (let item of options) {
const { test, mock: callback } = item
// custom不存在时,进行url参数匹配
const matched = (!test.custom) && doTest(configBackup, test).matched
Copy link
Collaborator

@hiyuki hiyuki Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把test.custom的处理也放在doTest中吧,外面就只需要调用doTest就可以,把proxy和validate中使用doTest的地方也修改一下

@@ -81,6 +83,24 @@ export default class XFetch {
}
}

setMock (options) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

放到setProxy上面

@hiyuki
Copy link
Collaborator

hiyuki commented Mar 9, 2022

处理冲突

1 similar comment
@hiyuki
Copy link
Collaborator

hiyuki commented Mar 9, 2022

处理冲突


if (this.mockOptions) {
let mockData = requestMock(this.mockOptions, config)
if (isThenable(mockData)) return mockData
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mockData不能直接返回,我们的返回需要和真实response保持一致的数据结构


if (this.mockOptions) {
let mockData = requestMock(this.mockOptions, config)
if (isThenable(mockData)) return mockData
Copy link
Collaborator

@hiyuki hiyuki Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mockData不能直接返回,我们的返回需要和真实response保持一致的数据结构,以及需要处理跨平台差异(可调用目前已有的transformRes方法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants