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
Add meta
parameter to mapData callback
#456
base: master
Are you sure you want to change the base?
Conversation
…on query and json mutation factories
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.
I've found some critical problems in API and implementation. Please fix it before merge.
Moreover, I would like to ask you to add documentation for the feature in the API reference sections.
@@ -143,7 +146,10 @@ describe('createJsonMutation', () => { | |||
expect(listeners.onSuccess).toHaveBeenCalled(); | |||
expect(listeners.onSuccess).toHaveBeenCalledWith( | |||
expect.objectContaining({ | |||
result: null, | |||
result: { |
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.
🚨 It is breaking change, and I do not see any reasons to do it 🤔
We can just use { result, meta: { response: { headers } }, params }
, it won't break user's code and will work well for your use cases.
@@ -52,7 +52,12 @@ describe('fetch/json.response.data', () => { | |||
params: { body: {} }, | |||
}); | |||
|
|||
expect(watcher.listeners.onDoneData).toBeCalledWith({ test: 'value' }); | |||
expect(watcher.listeners.onDoneData).toBeCalledWith({ |
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.
🤓 in my opinion, { result, meta: { response: { headers } } }
would be better to mirror the final structure in Queries
@@ -214,9 +214,43 @@ export function createJsonMutation(config: any): Mutation<any, any, any> { | |||
response: { status: config.response.status }, | |||
}); | |||
|
|||
let responseHeaders: Record<string, string> = {}; |
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.
🚨 it's broken:
- In the case of two concurrent runs of Mutation, headers can be mixed up
- It does not support Scope API and will be broken during SSR/tests/Storybook
@@ -324,6 +324,38 @@ export function createJsonQuery(config: any) { | |||
}, | |||
}); | |||
|
|||
let responseHeaders: Record<string, string> = {}; |
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.
🚨 same
No description provided.