Skip to content

Commit e2a0fe7

Browse files
authored
Improves observable recomputation logic (microsoft#189353)
1 parent 89a9017 commit e2a0fe7

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/vs/base/common/observableInternal/derived.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,11 @@ export class Derived<T, TChangeSummary = any> extends BaseObservable<T, void> im
110110
return result;
111111
} else {
112112
do {
113+
// We might not get a notification for a dependency that changed while it is updating,
114+
// thus we also have to ask all our depedencies if they changed in this case.
113115
if (this.state === DerivedState.dependenciesMightHaveChanged) {
114-
// We might not get a notification for a dependency that changed while it is updating,
115-
// thus we also have to ask all our depedencies if they changed in this case.
116-
this.state = DerivedState.upToDate;
117-
118116
for (const d of this.dependencies) {
119-
/** might call {@link handleChange} indirectly, which could invalidate us */
117+
/** might call {@link handleChange} indirectly, which could make us stale */
120118
d.reportChanges();
121119

122120
if (this.state as DerivedState === DerivedState.stale) {
@@ -126,6 +124,12 @@ export class Derived<T, TChangeSummary = any> extends BaseObservable<T, void> im
126124
}
127125
}
128126

127+
// We called report changes of all dependencies.
128+
// If we are still not stale, we can assume to be up to date again.
129+
if (this.state === DerivedState.dependenciesMightHaveChanged) {
130+
this.state = DerivedState.upToDate;
131+
}
132+
129133
this._recomputeIfNeeded();
130134
// In case recomputation changed one of our dependencies, we need to recompute again.
131135
} while (this.state !== DerivedState.upToDate);

0 commit comments

Comments
 (0)