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(core): recompute dependents in edge cases #2742

Merged
merged 9 commits into from
Oct 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into bug-2738
  • Loading branch information
dai-shi committed Oct 8, 2024
commit b94deb964e9cabfc0b1e60f4b1f65bcb4cc7a032
22 changes: 22 additions & 0 deletions tests/vanilla/dependency.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,25 @@ it('should not re-evaluate stable derived atom values in situations where depend
expect(store.get(newAtom)).toBe(3)
expect(callCounter).toHaveBeenCalledTimes(2)
})

it('handles complex dependency chains', async () => {
const baseAtom = atom(1)
const derived1 = atom((get) => get(baseAtom) * 2)
const derived2 = atom((get) => get(derived1) + 1)
let resolve = () => {}
const asyncDerived = atom(async (get) => {
const value = get(derived2)
await new Promise<void>((r) => (resolve = r))
return value * 2
})

const store = createStore()
const promise = store.get(asyncDerived)
resolve()
expect(await promise).toBe(6)

store.set(baseAtom, 2)
const promise2 = store.get(asyncDerived)
resolve()
expect(await promise2).toBe(10)
})
You are viewing a condensed version of this merge commit. You can view the full changes here.