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(core,query): handle edge cases with writeAtom returning a promise #701

Merged
merged 4 commits into from
Sep 11, 2021

Conversation

dai-shi
Copy link
Member

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

#689 changed writeAtom to return a promise. This is a follow-up PR to cover some edge cases.

  • remove extra code in code that is basically unnecessary in jotai core
  • make atomWithQuery write function to return a promise with fixing tests in jotai/query

@vercel
Copy link

vercel bot commented Sep 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/C62GeUBwB1xsEKy4xGPAd5DhAHF4
✅ Preview: https://jotai-git-fix-follow-returning-promise-pmndrs.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 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 7036fae:

Sandbox Source
React Configuration
React Typescript Configuration
React Browserify Configuration
React Snowpack Configuration
Next.js Configuration

Copy link
Collaborator

@Thisen Thisen left a comment

Choose a reason for hiding this comment

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

Looks good, feel like it's missing a test.

flushPending()
})
return
return writePromise.then(() => writeAtomState(atom, update))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to write a test for this inside core?

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 don't know. I can try. Do you know what this does?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I'm not sure if we need this, as now writeAtom returns a promise.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What I meant, is if you can write a test inside core, for the edge cases - Not the particular line. I'm sorry for not being clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I wasn't clear. You made a good point, we don't have a test for this, even if you don't know what it does.
The reason we didn't have a test is because we didn't know the actual use case.
Now, I feel like this isn't necessary at all. I will remove it completely.

): void => {
const [atomState] = wipAtomState(atom)
if (promise) {
atomState.w = promise
} else {
} else if (atomState.w === prevPromise) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you explain this with a comment?

Copy link
Collaborator

@Thisen Thisen left a comment

Choose a reason for hiding this comment

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

LGTM, only one nitpick request. :-)

@dai-shi dai-shi merged commit a22e0e5 into main Sep 11, 2021
@dai-shi dai-shi deleted the fix/follow-returning-promise branch September 11, 2021 12:32
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