Skip to content
Merged
18 changes: 18 additions & 0 deletions tests/vanilla/store.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,24 @@ it('recomputes dependents of unmounted atoms', () => {
expect(bRead).not.toHaveBeenCalled()
})

it('recomputes all changed atom dependents together', async () => {
const a = atom([0])
const b = atom([0])
const a0 = atom((get) => get(a)[0]!)
const b0 = atom((get) => get(b)[0]!)
const a0b0 = atom((get) => [get(a0), get(b0)])
const w = atom(null, (_, set) => {
set(a, [0])
set(b, [1])
})
const store = createStore()
store.sub(a0b0, () => {})
store.set(w)
expect(store.get(a0)).toBe(0)
expect(store.get(b0)).toBe(1)
expect(store.get(a0b0)).toEqual([0, 1])
})

it('should not inf on subscribe or unsubscribe', async () => {
const store = createStore()
const countAtom = atom(0)
Expand Down
Loading