@@ -23,6 +23,41 @@ export function autorunHandleChanges<TChangeSummary>(
2323 return new AutorunObserver ( debugName , fn , options . createEmptyChangeSummary , options . handleChange ) ;
2424}
2525
26+ // TODO@hediet rename to autorunWithStore
27+ export function autorunWithStore2 (
28+ debugName : string ,
29+ fn : ( reader : IReader , store : DisposableStore ) => void ,
30+ ) : IDisposable {
31+ return autorunWithStore ( fn , debugName ) ;
32+ }
33+
34+ export function autorunWithStoreHandleChanges < TChangeSummary > (
35+ debugName : string ,
36+ options : {
37+ createEmptyChangeSummary ?: ( ) => TChangeSummary ;
38+ handleChange : ( context : IChangeContext , changeSummary : TChangeSummary ) => boolean ;
39+ } ,
40+ fn : ( reader : IReader , changeSummary : TChangeSummary , store : DisposableStore ) => void
41+ ) : IDisposable {
42+ const store = new DisposableStore ( ) ;
43+ const disposable = autorunHandleChanges (
44+ debugName ,
45+ {
46+ createEmptyChangeSummary : options . createEmptyChangeSummary ,
47+ handleChange : options . handleChange ,
48+ } ,
49+ ( reader , changeSummary ) => {
50+ store . clear ( ) ;
51+ fn ( reader , changeSummary , store ) ;
52+ }
53+ ) ;
54+ return toDisposable ( ( ) => {
55+ disposable . dispose ( ) ;
56+ store . dispose ( ) ;
57+ } ) ;
58+ }
59+
60+ // TODO@hediet deprecate, rename to autorunWithStoreEx
2661export function autorunWithStore (
2762 fn : ( reader : IReader , store : DisposableStore ) => void ,
2863 debugName : string
@@ -144,13 +179,13 @@ export class AutorunObserver<TChangeSummary = any> implements IObserver, IReader
144179 }
145180
146181 public handlePossibleChange ( observable : IObservable < any > ) : void {
147- if ( this . state === AutorunState . upToDate && this . dependencies . has ( observable ) ) {
182+ if ( this . state === AutorunState . upToDate && this . dependencies . has ( observable ) && ! this . dependenciesToBeRemoved . has ( observable ) ) {
148183 this . state = AutorunState . dependenciesMightHaveChanged ;
149184 }
150185 }
151186
152187 public handleChange < T , TChange > ( observable : IObservable < T , TChange > , change : TChange ) : void {
153- if ( this . dependencies . has ( observable ) ) {
188+ if ( this . dependencies . has ( observable ) && ! this . dependenciesToBeRemoved . has ( observable ) ) {
154189 const shouldReact = this . _handleChange ? this . _handleChange ( {
155190 changedObservable : observable ,
156191 change,
0 commit comments