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

Add meta parameter to mapData callback #456

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

Conversation

efremenkovan
Copy link

No description provided.

Copy link
Owner

@igorkamyshev igorkamyshev left a 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: {
Copy link
Owner

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({
Copy link
Owner

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> = {};
Copy link
Owner

Choose a reason for hiding this comment

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

🚨 it's broken:

  1. In the case of two concurrent runs of Mutation, headers can be mixed up
  2. 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> = {};
Copy link
Owner

Choose a reason for hiding this comment

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

🚨 same

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

2 participants