Skip to content

Commit

Permalink
fix #2086 with a different approach
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Sep 2, 2023
1 parent c3023c2 commit 1d87a73
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/vanilla/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,17 @@ export const createStore = () => {
const recomputeDependents = (atom: AnyAtom): void => {
const dependencyMap = new Map<AnyAtom, Set<AnyAtom>>()
const dirtyMap = new WeakMap<AnyAtom, number>()
const getDependents = (a: AnyAtom): Dependents => {
const dependents = new Set(mountedMap.get(a)?.t)
pendingMap.forEach((_, pendingAtom) => {
if (getAtomState(pendingAtom)?.d.has(a)) {
dependents.add(pendingAtom)
}
})
return dependents
}
const loop1 = (a: AnyAtom) => {
const mounted = mountedMap.get(a)
mounted?.t.forEach((dependent) => {
getDependents(a).forEach((dependent) => {
if (dependent !== a) {
dependencyMap.set(
dependent,
Expand All @@ -480,8 +488,7 @@ export const createStore = () => {
}
loop1(atom)
const loop2 = (a: AnyAtom) => {
const mounted = mountedMap.get(a)
mounted?.t.forEach((dependent) => {
getDependents(a).forEach((dependent) => {
if (dependent !== a) {
let dirtyCount = dirtyMap.get(dependent)
if (dirtyCount) {
Expand Down

0 comments on commit 1d87a73

Please sign in to comment.