From 2b73c0706a4db6599976dff0eac6bdc21c219e83 Mon Sep 17 00:00:00 2001 From: David Maskasky Date: Sat, 14 Dec 2024 20:32:16 -0800 Subject: [PATCH] add task delay for some unknown reason to make this test pass --- src/vanilla/store.ts | 26 ++++++++++---------------- tests/vanilla/store.test.tsx | 1 + 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/vanilla/store.ts b/src/vanilla/store.ts index 42c0c2a439..fedd405d53 100644 --- a/src/vanilla/store.ts +++ b/src/vanilla/store.ts @@ -104,8 +104,8 @@ type AtomState = { v?: Value /** Atom error */ e?: AnyError - /** Indicates whether the atom value is has been changed */ - x?: boolean + /** Indicates that the atom value has been changed */ + x?: true } const isAtomStateInitialized = (atomState: AtomState) => @@ -446,24 +446,18 @@ const buildStore = ( atom: AnyAtom, atomState: AtomState, ) => { - atomState.x = false + delete atomState.x pending[0].delete(atom) } const isPendingRecompute = (atom: AnyAtom) => getAtomState(atom).x - const getMountedDependents = ( - pending: Pending, - a: AnyAtom, - aState: AtomState, - ) => { - return new Set( - [ - ...(aState.m?.t || []), - ...aState.p, - ...(getPendingDependents(pending, a) || []), - ].filter((a) => getAtomState(a).m), - ) + const getDependents = (pending: Pending, a: AnyAtom, aState: AtomState) => { + return new Set([ + ...(aState.m?.t || []), + ...aState.p, + ...(getPendingDependents(pending, a) || []), + ]) } /** @returns map of all dependents or dependencies (deep) of the root atoms */ @@ -492,7 +486,7 @@ const buildStore = ( } const getAllDependents = (pending: Pending, atoms: Iterable) => - getDeep((a, aState) => getMountedDependents(pending, a, aState), atoms) + getDeep((a, aState) => getDependents(pending, a, aState), atoms) // This is a topological sort via depth-first search, slightly modified from // what's described here for simplicity and performance reasons: diff --git a/tests/vanilla/store.test.tsx b/tests/vanilla/store.test.tsx index 2d978ad545..ef3fd55999 100644 --- a/tests/vanilla/store.test.tsx +++ b/tests/vanilla/store.test.tsx @@ -340,6 +340,7 @@ it('resolves dependencies reliably after a delay (#2192)', async () => { await waitFor(() => assert(resolve.length === 1)) resolve[0]!() + await new Promise((r) => setTimeout(r)) const increment = (c: number) => c + 1 store.set(countAtom, increment) store.set(countAtom, increment)