Skip to content

Commit

Permalink
add task delay for some unknown reason to make this test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaskasky committed Dec 15, 2024
1 parent 1e9d058 commit 2b73c07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/vanilla/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ type AtomState<Value = AnyValue> = {
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 = <Value>(atomState: AtomState<Value>) =>
Expand Down Expand Up @@ -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<AnyAtom>(
[
...(aState.m?.t || []),
...aState.p,
...(getPendingDependents(pending, a) || []),
].filter((a) => getAtomState(a).m),
)
const getDependents = (pending: Pending, a: AnyAtom, aState: AtomState) => {
return new Set<AnyAtom>([
...(aState.m?.t || []),
...aState.p,
...(getPendingDependents(pending, a) || []),
])
}

/** @returns map of all dependents or dependencies (deep) of the root atoms */
Expand Down Expand Up @@ -492,7 +486,7 @@ const buildStore = (
}

const getAllDependents = (pending: Pending, atoms: Iterable<AnyAtom>) =>
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:
Expand Down
1 change: 1 addition & 0 deletions tests/vanilla/store.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2b73c07

Please sign in to comment.