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

[WIP] fix(core): expose unstable_resolve instead of unstable_is #2609

Closed
wants to merge 6 commits into from

Conversation

dmaskasky
Copy link
Collaborator

@dmaskasky dmaskasky commented Jun 7, 2024

Related Issues or Discussions

Replaces PR: #2569

Context

jotai-scope implementation can be made simpler if the store exposed the ability to customize which atom config to reference based on another atom config.

Summary

unstable_resolve is a new store method. This method customizes how atoms are resolved by their atom config (e.g. using an atom as a key to look up another atom). By default the resolve behavior is atom => atom.

ResolveAtom Invocation Sites

The following functions convert their atom arg to a resolved atom. Since these six functions cover the store interface, it is not necessary to call resolveAtom elsewhere.

  1. readAtom
  2. writeAtom
  3. subscribeAtom
  4. readAtomState -> getter
  5. writeAtomState -> getter
  6. writeAtomState -> setter

Note: store dev methods do not call resolveAtom. The caller of these dev methods is expected to handle atom resolution.

Example

const pseudo = atom('pseudo')
const a = atom('a')
const store = createStore()
store.unstable_resolve = (atom) => atom === pseudo ? a : atom
expect(store.get(pseudo)).toBe('a')

TODO

  1. Determine if this change is sufficient for jotai-scope

Check List

  • pnpm run prettier for formatting code and docs

Copy link

vercel bot commented Jun 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jotai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 5:59pm

Copy link

codesandbox-ci bot commented Jun 7, 2024

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.

@dmaskasky dmaskasky changed the base branch from expose-store-get-atom to main June 7, 2024 02:03
Copy link

github-actions bot commented Jun 7, 2024

LiveCodes Preview in LiveCodes

Latest commit: 9ec28ce
Last updated: Jun 24, 2024 5:58pm (UTC)

Playground Link
React demo https://livecodes.io?x=id/CNM5S8ZNH

See documentations for usage instructions.

@dmaskasky dmaskasky force-pushed the expose-store-get-atom-2 branch from 6102035 to 896bc81 Compare June 7, 2024 02:15
@dmaskasky dmaskasky changed the base branch from main to expose-store-get-atom June 7, 2024 02:15
@dmaskasky dmaskasky changed the base branch from expose-store-get-atom to main June 7, 2024 02:15
Copy link

codesandbox-ci bot commented Jun 7, 2024

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.

Copy link

codesandbox-ci bot commented Jun 7, 2024

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.

@dmaskasky dmaskasky changed the title Expose store get atom 2 [WIP] Expose store get atom 2 Jun 7, 2024
@dmaskasky dmaskasky force-pushed the expose-store-get-atom-2 branch from 2480e0b to 18e83e7 Compare June 7, 2024 21:38
Copy link

codesandbox-ci bot commented Jun 7, 2024

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.

Copy link

codesandbox-ci bot commented Jun 7, 2024

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.

Copy link

codesandbox-ci bot commented Jun 7, 2024

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.

Copy link

codesandbox-ci bot commented Jun 7, 2024

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.

Copy link

codesandbox-ci bot commented Jun 7, 2024

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.

@dmaskasky dmaskasky changed the title [WIP] Expose store get atom 2 Expose store get atom 2 Jun 7, 2024
@dmaskasky dmaskasky force-pushed the expose-store-get-atom-2 branch 2 times, most recently from 008323a to 3acc1b9 Compare June 7, 2024 23:25
Copy link

codesandbox-ci bot commented Jun 7, 2024

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.

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

This looks super cool! Thanks for your contribution.
Now, this PR fixes both store and store2, I think it can be released as a patch.

Copy link

codesandbox-ci bot commented Jun 19, 2024

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.

@dai-shi dai-shi changed the title Expose store get atom 2 fix(core): expose unstable_resolve instead of unstable_is Jun 19, 2024
@dmaskasky dmaskasky force-pushed the expose-store-get-atom-2 branch from 89fe100 to 7e259b9 Compare June 24, 2024 02:06
@dmaskasky dmaskasky changed the title fix(core): expose unstable_resolve instead of unstable_is [WIP] fix(core): expose unstable_resolve instead of unstable_is Jun 24, 2024
@dmaskasky
Copy link
Collaborator Author

[DO_NOT_MERGE] I am still trying to understand whether this change will satisfy the needs of jotai-scope. I might go in a slightly different direction.

dai-shi and others added 6 commits June 24, 2024 10:58
Co-authored-by: David Maskasky <dmaskasky@otter.ai>
* add failing tests for unstable_resolve

* Apply suggestions from code review

* Apply suggestions from code review

* Update tests/vanilla/store.test.tsx

* hack types

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
Co-authored-by: daishi <daishi@axlight.com>
@dmaskasky dmaskasky force-pushed the expose-store-get-atom-2 branch from 7e259b9 to 9ec28ce Compare June 24, 2024 17:58
@dai-shi dai-shi marked this pull request as draft June 24, 2024 22:51
dai-shi added a commit that referenced this pull request Jul 10, 2024
dai-shi pushed a commit that referenced this pull request Jul 10, 2024
@dmaskasky dmaskasky closed this Jul 16, 2024
@dmaskasky dmaskasky deleted the expose-store-get-atom-2 branch July 16, 2024 16:54
dai-shi added a commit that referenced this pull request Aug 13, 2024
* experimental(core): expose unstable_derive instead of unstable_is

* chore: remove empty line

* chore types

* follow resolveAtom in #2609

* store test from #2609

* adjust store.test.tsx for unstable_derive

* limit atom state map type

* add test with atom state map

* update test using unstable_derive

* drop resolveAtom, add derive atom test

* simplify unstable_derive

* wip: this works but i do not like it

* separate atomstate and atomcontext

* for old ts

* fix

* fix 2

* simplify a bit with dev breaking changes

* revert to bd9c6c0, except for new test

* refactor (skipping the new test for now)

* refactor 2

* revert those refactors :-p

* wip: hm, how is bundle size?

* fix tests

* add test for unstable_derive (#2665)

* add a failing test

* wip: failed attempt

* split unstable_derive test

* wip: failed attempt 2

* revert failing tests

* empty commit

* restore unstable_is of now (we will remove it in the later version.)

---------

Co-authored-by: David Maskasky <dmaskasky@gmail.com>
Co-authored-by: David Maskasky <dmaskasky@otter.ai>
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