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

refactor(store): prefer epoch number comparisons to indicate value change #2828

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

dmaskasky
Copy link
Collaborator

Summary

Replaces value comparisons with epoch number changes. This may help prevent memory leaks.

Check List

  • pnpm run prettier for formatting code and docs

Copy link

vercel bot commented Nov 18, 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 Nov 18, 2024 0:59am

Copy link

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

LiveCodes Preview in LiveCodes

Latest commit: 92a1b8e
Last updated: Nov 18, 2024 12:58am (UTC)

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

See documentations for usage instructions.

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.

LGTM! Nice finding.

const v = args[0] as V
setAtomStateValueOrPromise(a, aState, v)
mountDependencies(pending, a, aState)
if (!hasPrevValue || !Object.is(prevValue, aState.v)) {
if (prevEpochNumber !== aState.n) {
Copy link
Member

Choose a reason for hiding this comment

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

This looks really good and I probably missed it when introducing the epoch number.

My concern was for the error case, but the epoch number is incremented with delete atomState.v, so it should be fine.

@dai-shi dai-shi changed the title prefer epoch number comparisons to indicate value change refactor(store): prefer epoch number comparisons to indicate value change Nov 18, 2024
@dai-shi dai-shi added this to the v2.10.3 milestone Nov 18, 2024
@dai-shi dai-shi merged commit 14c028a into pmndrs:main Nov 18, 2024
40 checks passed
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