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(core): replace batch dependents map with batched changed atoms #2912

Merged
merged 5 commits into from
Jan 7, 2025

Conversation

dmaskasky
Copy link
Collaborator

@dmaskasky dmaskasky commented Jan 6, 2025

Summary

Batch.D was previously Map<Atom, Set<AtomDependent>>.
This allowed atom dependents to recompute without being mounted. There isn't an obvious reason to do so.
All tests pass after removing this functionality.

Dropped behavior

After this change, the following test would fail.
I don't think we should be update dependents of unmounted atoms.

it('recomputes dependents of unmounted atoms', () => {
  const a = atom(0)
  const bRead = vi.fn((get) => get(a))
  const b = atom(bRead)
  const c = atom((get) => get(b))
  const w = atom(null, (get, set) => {
    set(a, 1) // batch.D.set(a, new Set())
    get(c) // batch.D.get(a).add(b)
    set(a, 2) // topSortedReversed: [b, a]
    bRead.mockClear()
    // after this write function completes, flushBatch will recompute `a` and `b`
    // note: a and b are not mounted
  })
  const store = createStore()
  store.set(w)
  expect(bRead).toHaveBeenCalled()
})

Check List

  • pnpm run fix:format for formatting code and docs

Copy link

vercel bot commented Jan 6, 2025

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 Jan 7, 2025 0:17am

Copy link

codesandbox-ci bot commented Jan 6, 2025

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

pkg-pr-new bot commented Jan 6, 2025

Open in Stackblitz

More templates

npm i https://pkg.pr.new/jotai@2912

commit: fe7c699

Copy link

github-actions bot commented Jan 6, 2025

Size Change: -527 B (-0.57%)

Total Size: 92.1 kB

Filename Size Change
./dist/esm/vanilla.mjs 4.22 kB -103 B (-2.38%)
./dist/system/vanilla.development.js 4.31 kB -101 B (-2.29%)
./dist/system/vanilla.production.js 2.17 kB -51 B (-2.29%)
./dist/umd/vanilla.development.js 5.68 kB -116 B (-2%)
./dist/umd/vanilla.production.js 2.86 kB -39 B (-1.34%)
./dist/vanilla.js 5.56 kB -117 B (-2.06%)
ℹ️ View Unchanged
Filename Size
./dist/babel/plugin-debug-label.js 932 B
./dist/babel/plugin-react-refresh.js 1.14 kB
./dist/babel/preset.js 1.41 kB
./dist/esm/babel/plugin-debug-label.mjs 1 kB
./dist/esm/babel/plugin-react-refresh.mjs 1.19 kB
./dist/esm/babel/preset.mjs 1.49 kB
./dist/esm/index.mjs 62 B
./dist/esm/react.mjs 1.4 kB
./dist/esm/react/utils.mjs 746 B
./dist/esm/utils.mjs 67 B
./dist/esm/vanilla/utils.mjs 5.04 kB
./dist/index.js 242 B
./dist/react.js 1.44 kB
./dist/react/utils.js 1.39 kB
./dist/system/babel/plugin-debug-label.development.js 1.1 kB
./dist/system/babel/plugin-debug-label.production.js 775 B
./dist/system/babel/plugin-react-refresh.development.js 1.29 kB
./dist/system/babel/plugin-react-refresh.production.js 928 B
./dist/system/babel/preset.development.js 1.59 kB
./dist/system/babel/preset.production.js 1.14 kB
./dist/system/index.development.js 252 B
./dist/system/index.production.js 183 B
./dist/system/react.development.js 1.56 kB
./dist/system/react.production.js 864 B
./dist/system/react/utils.development.js 860 B
./dist/system/react/utils.production.js 462 B
./dist/system/utils.development.js 257 B
./dist/system/utils.production.js 187 B
./dist/system/vanilla/utils.development.js 5.25 kB
./dist/system/vanilla/utils.production.js 3.14 kB
./dist/umd/babel/plugin-debug-label.development.js 1.08 kB
./dist/umd/babel/plugin-debug-label.production.js 852 B
./dist/umd/babel/plugin-react-refresh.development.js 1.27 kB
./dist/umd/babel/plugin-react-refresh.production.js 1 kB
./dist/umd/babel/preset.development.js 1.54 kB
./dist/umd/babel/preset.production.js 1.22 kB
./dist/umd/index.development.js 383 B
./dist/umd/index.production.js 328 B
./dist/umd/react.development.js 1.57 kB
./dist/umd/react.production.js 936 B
./dist/umd/react/utils.development.js 1.53 kB
./dist/umd/react/utils.production.js 1.01 kB
./dist/umd/utils.development.js 399 B
./dist/umd/utils.production.js 342 B
./dist/umd/vanilla/utils.development.js 6.24 kB
./dist/umd/vanilla/utils.production.js 3.78 kB
./dist/utils.js 247 B
./dist/vanilla/utils.js 6.1 kB

compressed-size-action

Copy link

github-actions bot commented Jan 6, 2025

LiveCodes Preview in LiveCodes

Latest commit: fe7c699
Last updated: Jan 7, 2025 12:16pm (UTC)

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

See documentations for usage instructions.

@dai-shi
Copy link
Member

dai-shi commented Jan 6, 2025

wow, this looks cool. I will have a closer look later.

@dmaskasky dmaskasky requested a review from dai-shi January 6, 2025 08:38
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.

Oh, yes! This is something I wan't comfortable with. Thanks for fixing it. This goes towards what I have in mind. I'd like to go further.

Is this now possible because of .x?

Anyway, merging this.

@dai-shi dai-shi merged commit 9861266 into main Jan 7, 2025
43 checks passed
@dai-shi dai-shi deleted the batch-simplify branch January 7, 2025 12:20
@dai-shi dai-shi changed the title replace batch dependents map with batched changed atoms refactor(core): replace batch dependents map with batched changed atoms Jan 7, 2025
@dai-shi dai-shi added this to the v2.11.1 milestone Jan 7, 2025
dai-shi added a commit that referenced this pull request Jan 7, 2025
dai-shi added a commit that referenced this pull request Jan 7, 2025
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