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

New store implementation as store2.ts #2463

Merged
merged 29 commits into from
Apr 4, 2024
Merged

New store implementation as store2.ts #2463

merged 29 commits into from
Apr 4, 2024

Conversation

dai-shi
Copy link
Member

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

The current store implementation is based on the assumption I made in Jotai v1. Since then, it has changed and v2 design is slightly different. Technically speaking, in v1, we tried to support state branching (or state versioning) which we gave up in v2. So, the store implementation could be a little simpler. This PR introduces a new implementation with mutable atom state. Currently, we have a new store2.ts file and run tests to both store.ts and store2.ts. We hope to replace store.ts with store2.ts eventually. This is not the end, but the start. We might be able to simplify the new implementation and add some new capabilities. But, for now, the migration is important especially with/for jotai-devtools. It takes time.

Copy link

vercel bot commented Mar 25, 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 4, 2024 2:03am

Copy link

codesandbox-ci bot commented Mar 25, 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 Mar 25, 2024

Size Change: +18.3 kB (+25%) 🚨

Total Size: 90.6 kB

Filename Size Change
dist/system/vanilla.development.js 4.35 kB +21 B (0%)
dist/system/vanilla.production.js 2.17 kB -2 B (0%)
dist/umd/vanilla.development.js 5.22 kB +14 B (0%)
dist/umd/vanilla.production.js 2.79 kB +2 B (0%)
dist/vanilla.js 5.13 kB +16 B (0%)
dist/experimental.js 4.93 kB +4.93 kB (new file) 🆕
dist/system/experimental.development.js 3.85 kB +3.85 kB (new file) 🆕
dist/system/experimental.production.js 1.89 kB +1.89 kB (new file) 🆕
dist/umd/experimental.development.js 5.02 kB +5.02 kB (new file) 🆕
dist/umd/experimental.production.js 2.56 kB +2.56 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
dist/babel/plugin-debug-label.js 907 B
dist/babel/plugin-react-refresh.js 1.14 kB
dist/babel/preset.js 1.38 kB
dist/index.js 242 B
dist/react.js 1.06 kB
dist/react/utils.js 1.26 kB
dist/system/babel/plugin-debug-label.development.js 1.09 kB
dist/system/babel/plugin-debug-label.production.js 757 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.56 kB
dist/system/babel/preset.production.js 1.13 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 722 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 4.88 kB
dist/system/vanilla/utils.production.js 2.98 kB
dist/umd/babel/plugin-debug-label.development.js 1.06 kB
dist/umd/babel/plugin-debug-label.production.js 845 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.53 kB
dist/umd/babel/preset.production.js 1.24 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.43 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/utils.development.js 5.79 kB
dist/umd/vanilla/utils.production.js 3.59 kB
dist/utils.js 246 B
dist/vanilla/utils.js 5.65 kB

compressed-size-action

Copy link

github-actions bot commented Mar 25, 2024

LiveCodes Preview in LiveCodes

Latest commit: 72329c3
Last updated: Apr 4, 2024 2:02am (UTC)

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

See documentations for usage instructions.

@dai-shi
Copy link
Member Author

dai-shi commented Mar 25, 2024

Tagging those who might be interested: @arjunvegda @dmaskasky @backbone87 @iwoplaza

@dai-shi dai-shi changed the title wip: store2 New store implementation as store2.ts Mar 26, 2024
@dai-shi dai-shi marked this pull request as ready for review March 26, 2024 01:06
@dai-shi
Copy link
Member Author

dai-shi commented Mar 26, 2024

I will merge this for v2.8.0 as it changes the built result slightly.

@dai-shi dai-shi added this to the v2.8.0 milestone Mar 26, 2024
src/vanilla/store2.ts Outdated Show resolved Hide resolved
Co-authored-by: Iwo Plaza <iwoplaza@gmail.com>
*/
readonly d: Map<AnyAtom, { readonly v: AnyValue } | { readonly e: AnyError }>
/** Set of atoms that depends on the atom. */
readonly t: Set<AnyAtom>
Copy link
Member Author

Choose a reason for hiding this comment

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

As this holds a strong reference, it may cause memory leaks.
We should create a failing test case and fix it. (Probably by moving it to Mounted, or possibly with WeakRef but unlikely.)

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 bf075ef into main Apr 4, 2024
34 checks passed
@dai-shi dai-shi deleted the store2 branch April 4, 2024 02:13
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