@@ -196,7 +196,7 @@ export class Derived<T, TChangeSummary = any> extends BaseObservable<T, void> im
196196
197197 public handlePossibleChange < T > ( observable : IObservable < T , unknown > ) : void {
198198 // In all other states, observers already know that we might have changed.
199- if ( this . state === DerivedState . upToDate && this . dependencies . has ( observable ) ) {
199+ if ( this . state === DerivedState . upToDate && this . dependencies . has ( observable ) && ! this . dependenciesToBeRemoved . has ( observable ) ) {
200200 this . state = DerivedState . dependenciesMightHaveChanged ;
201201 for ( const r of this . observers ) {
202202 r . handlePossibleChange ( this ) ;
@@ -205,22 +205,19 @@ export class Derived<T, TChangeSummary = any> extends BaseObservable<T, void> im
205205 }
206206
207207 public handleChange < T , TChange > ( observable : IObservable < T , TChange > , change : TChange ) : void {
208- const isUpToDate = this . state === DerivedState . upToDate ;
209- let shouldReact = true ;
210-
211- if ( this . _handleChange && this . dependencies . has ( observable ) ) {
212- shouldReact = this . _handleChange ( {
208+ if ( this . dependencies . has ( observable ) && ! this . dependenciesToBeRemoved . has ( observable ) ) {
209+ const shouldReact = this . _handleChange ? this . _handleChange ( {
213210 changedObservable : observable ,
214211 change,
215212 didChange : o => o === observable as any ,
216- } , this . changeSummary ! ) ;
217- }
218-
219- if ( shouldReact && ( this . state === DerivedState . dependenciesMightHaveChanged || isUpToDate ) && this . dependencies . has ( observable ) ) {
220- this . state = DerivedState . stale ;
221- if ( isUpToDate ) {
222- for ( const r of this . observers ) {
223- r . handlePossibleChange ( this ) ;
213+ } , this . changeSummary ! ) : true ;
214+ const wasUpToDate = this . state === DerivedState . upToDate ;
215+ if ( shouldReact && ( this . state === DerivedState . dependenciesMightHaveChanged || wasUpToDate ) ) {
216+ this . state = DerivedState . stale ;
217+ if ( wasUpToDate ) {
218+ for ( const r of this . observers ) {
219+ r . handlePossibleChange ( this ) ;
220+ }
224221 }
225222 }
226223 }
0 commit comments