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(util): atomWithDefault #379

Merged
merged 10 commits into from
Mar 27, 2021
Merged

feat(util): atomWithDefault #379

merged 10 commits into from
Mar 27, 2021

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Mar 25, 2021

Close #352

  • impl
  • tests
  • docs

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 25, 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 130e2e1:

Sandbox Source
React Configuration
React Typescript Configuration

@dai-shi dai-shi changed the title wip: atom with default util feat(util): atomWithDefault Mar 25, 2021
@dai-shi dai-shi marked this pull request as ready for review March 25, 2021 12:51
@dai-shi dai-shi requested a review from Thisen March 25, 2021 12:52
@aulneau
Copy link
Collaborator

aulneau commented Mar 26, 2021

This is a great helper, I was wondering if it makes sense to have atomFamilyWithDefault, too?

@dai-shi
Copy link
Member Author

dai-shi commented Mar 26, 2021

This is a great helper, I was wondering if it makes sense to have atomFamilyWithDefault, too?

tbh, i'm not very happy with it. we have atomWithReset too. we may have more helpers in the future.
I now think it's better if atomFamily takes atom creator instead of read/write.

const myFamily = atomFamily(param => atom(...))
// then this is possible
const myFamily = atomFamily(param => atomWithDefault(...))

what do you think? worth a breaking change before v1?

@aulneau
Copy link
Collaborator

aulneau commented Mar 26, 2021

what do you think? worth a breaking change before v1?

I do think so.

I have noticed that for any of the utility atoms, I've been needing to wrap them with other kinds. such as wishing i could do atomFamilyWithQuery. I could also see a need for something like this atomFamilyWithDefaultWithQuery lol (naming just for functional example)

@dai-shi
Copy link
Member Author

dai-shi commented Mar 26, 2021

Okay, the type would be much better too. Let's do that.
Would you or anyone like to work on it? I'm happy to take it if nobody raises a hand.
Maybe we want to create a dedicated issue at first.

@dai-shi
Copy link
Member Author

dai-shi commented Mar 27, 2021

Maybe we want to create a dedicated issue at first.

Done: #385

@dai-shi dai-shi requested a review from Thisen March 27, 2021 01:14
@dai-shi
Copy link
Member Author

dai-shi commented Mar 27, 2021

Thanks for the review. I will merge this later with others.

@dai-shi dai-shi merged commit 42db545 into master Mar 27, 2021
@dai-shi dai-shi deleted the feat/atom-with-default branch March 27, 2021 14:31
@dai-shi dai-shi mentioned this pull request Mar 27, 2021
49 tasks
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.

Writeable Atom with derived default value
3 participants