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(store): remove dev3 methods and add dev4 methods only in store2 #2484

Merged
merged 13 commits into from
Apr 8, 2024

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Apr 5, 2024

base pr #2474

Copy link

vercel bot commented Apr 5, 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 Apr 8, 2024 1:17am

Copy link

codesandbox-ci bot commented Apr 5, 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

github-actions bot commented Apr 5, 2024

Size Change: -3.01 kB (-3%)

Total Size: 90.2 kB

Filename Size Change
dist/experimental.js 4.29 kB -842 B (-16%) 👏
dist/system/experimental.development.js 3.41 kB -563 B (-14%) 👏
dist/system/experimental.production.js 1.89 kB -1 B (0%)
dist/system/vanilla.development.js 4.31 kB -187 B (-4%)
dist/system/vanilla.production.js 2.17 kB +1 B (0%)
dist/umd/experimental.development.js 4.38 kB -856 B (-16%) 👏
dist/umd/experimental.production.js 2.56 kB -2 B (0%)
dist/umd/vanilla.development.js 5.19 kB -282 B (-5%)
dist/vanilla.js 5.1 kB -278 B (-5%)
ℹ️ View Unchanged
Filename Size
dist/babel/plugin-debug-label.js 927 B
dist/babel/plugin-react-refresh.js 1.14 kB
dist/babel/preset.js 1.4 kB
dist/index.js 242 B
dist/react.js 1.06 kB
dist/react/utils.js 1.42 kB
dist/system/babel/plugin-debug-label.development.js 1.1 kB
dist/system/babel/plugin-debug-label.production.js 771 B
dist/system/babel/plugin-react-refresh.development.js 1.29 kB
dist/system/babel/plugin-react-refresh.production.js 929 B
dist/system/babel/preset.development.js 1.58 kB
dist/system/babel/preset.production.js 1.14 kB
dist/system/index.development.js 253 B
dist/system/index.production.js 182 B
dist/system/react.development.js 1.18 kB
dist/system/react.production.js 711 B
dist/system/react/utils.development.js 860 B
dist/system/react/utils.production.js 461 B
dist/system/utils.development.js 258 B
dist/system/utils.production.js 188 B
dist/system/vanilla/utils.development.js 5.07 kB
dist/system/vanilla/utils.production.js 3.12 kB
dist/umd/babel/plugin-debug-label.development.js 1.08 kB
dist/umd/babel/plugin-debug-label.production.js 855 B
dist/umd/babel/plugin-react-refresh.development.js 1.28 kB
dist/umd/babel/plugin-react-refresh.production.js 1.01 kB
dist/umd/babel/preset.development.js 1.54 kB
dist/umd/babel/preset.production.js 1.22 kB
dist/umd/index.development.js 381 B
dist/umd/index.production.js 329 B
dist/umd/react.development.js 1.18 kB
dist/umd/react.production.js 785 B
dist/umd/react/utils.development.js 1.55 kB
dist/umd/react/utils.production.js 1.03 kB
dist/umd/utils.development.js 398 B
dist/umd/utils.production.js 343 B
dist/umd/vanilla.production.js 2.79 kB
dist/umd/vanilla/utils.development.js 5.99 kB
dist/umd/vanilla/utils.production.js 3.77 kB
dist/utils.js 246 B
dist/vanilla/utils.js 5.86 kB

compressed-size-action

Copy link

github-actions bot commented Apr 5, 2024

LiveCodes Preview in LiveCodes

Latest commit: d742660
Last updated: Apr 8, 2024 1:16am (UTC)

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

See documentations for usage instructions.

@dai-shi dai-shi changed the title fix(store): combine dev3 methods fix(store): remove dev3 methods and add dev4 methods only in store2 Apr 6, 2024
Comment on lines +606 to +608
dev4_get_internal_weak_map: () => atomStateMap,
dev4_override_method: (key, fn) => {
;(store as any)[key] = fn
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! A few questions

  1. With this approach users would probably need to composeWithDevTools(store || getDefaultStore()) and supply it via <Provider/> to their application. So the DevTools would no longer support the provider-less mode unless if we keep composeWithDevTools function within the main lib. Any thoughts around this? 🤔

  2. What would be the best way to wait for atoms resolving a promise (in DevTools)? i.e. values changing from sync -> async or async -> async (new promise). This did not exist in v1 btw, but would be nice to
    include it in v2

  3. Could we still keep mountedAtoms around? Perhaps we could introduce dev4_get_internal_mounted_atom_map? If you feel strongly about not including it, then I could start with keeping references to the atoms changed with subscribe/unsubscribe 🤔

  4. Do we still need dev4 prefix or should we call it dev_get_internal_weak_map etc.? From Jotai DevTools perspective, exposing import { DevTools } from 'jotai-devtools/experimental might make more sense that eliminates any conflict with the dev vs dev4

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. With this approach users would probably need to composeWithDevTools(store || getDefaultStore()) and supply it via <Provider/> to their application. So the DevTools would no longer support the provider-less mode unless if we keep composeWithDevTools function within the main lib. Any thoughts around this?

I thought without dev4_override_method, that's the case, and hoped dev4_override_method could work it around.

Copy link
Member Author

Choose a reason for hiding this comment

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

2. What would be the best way to wait for atoms resolving a promise (in DevTools)?

I assume you can simply await the promise value from store.get().

Copy link
Member Author

Choose a reason for hiding this comment

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

3. Could we still keep mountedAtoms around?

Hmm, that was one of the biggest things, I would like to avoid in dev4. Otherwise, we can re-consider dev3.

Copy link
Member Author

Choose a reason for hiding this comment

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

4. Do we still need dev4 prefix or

I don't understand what conflicts. I prefer the revision number for clearer communication. (we may have dev5 in the future.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought without dev4_override_method, that's the case, and hoped dev4_override_method could work it around.

Since it is updating the reference of the store it should work with the default store too 🤔

Hmm, that was one of the biggest things, I would like to avoid in dev4. Otherwise, we can re-consider dev3.

I can work around it by patching store.set and manually keeping track of the atoms by sub and unsub. Not sure if I'm missing any edge cases here.

I don't understand what conflicts.

Mostly TypeScript related, I'm trying to avoid the number of type guards 😅 but I can circumvent it.

Copy link
Collaborator

@arjunvegda arjunvegda left a comment

Choose a reason for hiding this comment

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

Thanks a lot for adding this! I tested a bunch of scenarios out locally and seems promising so far.

type Store =
| (PrdStore & Partial<DevStoreRev2>)
| (PrdStore & DevStoreRev2 & DevStoreRev3)
type Store = PrdStore | (PrdStore & DevStoreRev4)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any chance we could export PrdStore & DevStoreRev4?

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 can do that.

@dai-shi
Copy link
Member Author

dai-shi commented Apr 8, 2024

seems promising so far.

Thanks, and we can modify/improve it (and adding more tests for dev4_ methods) moving forward. I don't think store2 is ready yet anyway. for example #2477

@dai-shi dai-shi merged commit a3be09e into main Apr 8, 2024
37 checks passed
@dai-shi dai-shi deleted the fix/dev3_methods branch April 8, 2024 01:39
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