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

fix: support atom scope outside core #589

Merged
merged 2 commits into from
Jul 15, 2021
Merged

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Jul 11, 2021

An internal discussion with @aulneau revealed that many of utils/integrations don't support atom scope properly, especially when we create internal atoms in a function.
This PR addresses the issue. Note this affects only the case using scope, which is mainly for library usage.

@dai-shi dai-shi requested a review from aulneau July 11, 2021 01:35
@vercel
Copy link

vercel bot commented Jul 11, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pmndrs/jotai/7S9VaUrKtTwJubPCE8tJxHLsHNkj
✅ Preview: https://jotai-git-fix-support-scope-outside-core-pmndrs.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 11, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit eb1471b:

Sandbox Source
React Configuration
React Typescript Configuration

Comment on lines 31 to 32
equalityFn: (a: TData, b: TData) => boolean = Object.is,
getQueryClient: (get: Getter) => QueryClient = (get) => get(queryClientAtom)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know there is a preference to avoid objects being passed, but I think this will result in a lot of atomWithQuery(createQuery, null, (get) => get(myQueryClientAtom)), as I think passing a custom query client will be used more often than an equalityFn. and maybe passing null is ok, too :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I see your point and yes to the preference.
I'm not sure how often people use myQueryClientAtom in app code. Unlike jotai/urql which require "URL", the default client in jotai/query would work for most cases?
We still can use <Provider initialValues={[[queryClientAtom, myQueryClient]]}>.

To allow null for equalityFn, we can't use default parameter, right? we can change that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We still can use <Provider initialValues={[[queryClientAtom, myQueryClient]]}>.

If we did this though, it would not allow you to modify the scope, right?

I think folks might use the custom query client often, esp if they have an app that is using react-query already as they might have defined defaults or other settings they want to use.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, for the custom atom scope, we need to use the third argument.
Do you think it's a good idea to swap the second and third arguments? (=breaking change)

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, I do. I'm honestly not sure how much use or importance the equalityFn provides -- i find modifying the query client to only update on certain changes is more effective https://react-query.tanstack.com/guides/migrating-to-react-query-3#the-queryoptionsnotifyonstatuschange-option-has-been-superceded-by-the-new-notifyonchangeprops-and-notifyonchangepropsexclusions-options

Copy link
Member Author

Choose a reason for hiding this comment

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

If we can remove equalityFn completely, it seems better to me. Is it possible?

Copy link
Member Author

Choose a reason for hiding this comment

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

@dai-shi dai-shi merged commit b6a7240 into master Jul 15, 2021
@dai-shi dai-shi deleted the fix/support-scope-outside-core branch July 15, 2021 09:52
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.

2 participants