Skip to content

Commit

Permalink
Merge branch 'main' into fix/onmount-setatom-subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Nov 17, 2024
2 parents 97285c5 + 1bf91ce commit 94b0b83
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/vanilla/dependency.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,15 @@ it('handles complex dependency chains', async () => {
resolve()
expect(await promise2).toBe(10)
})

it('can read sync derived atom in write without initializing', () => {
const store = createStore()
const a = atom(0)
const b = atom((get) => get(a) + 1)
const c = atom(null, (get, set) => set(a, get(b)))
store.set(c)
expect(store.get(a)).toBe(1)
store.set(c)
// note: this is why write get needs to update deps
expect(store.get(a)).toBe(2)
})

0 comments on commit 94b0b83

Please sign in to comment.