Przeglądaj źródła

Fix handling of observable disposal

Steven Silvester 7 lat temu
rodzic
commit
bf3ba3bc07

+ 4 - 2
packages/coreutils/src/modeldb.ts

@@ -282,7 +282,7 @@ class ObservableValue implements IObservableValue {
    *
    * @param initialValue: the starting value for the `ObservableValue`.
    */
-  constructor(initialValue: JSONValue = {}) {
+  constructor(initialValue: JSONValue = null) {
     this._value = initialValue;
   }
 
@@ -398,7 +398,7 @@ class ModelDB implements IModelDB {
    * Whether the database is disposed.
    */
   get isDisposed(): boolean {
-    return this._db === null;
+    return this._isDisposed;
   }
 
   /**
@@ -571,6 +571,7 @@ class ModelDB implements IModelDB {
     if (this.isDisposed) {
       return;
     }
+    this._isDisposed = true;
     if (this._toDispose) {
       this._db.dispose();
     }
@@ -590,6 +591,7 @@ class ModelDB implements IModelDB {
   private _basePath: string;
   private _db: ModelDB | ObservableMap<IObservable>;
   private _toDispose = false;
+  private _isDisposed = false;
   private _disposables = new DisposableSet();
 }
 

+ 4 - 2
packages/coreutils/src/observablemap.ts

@@ -189,7 +189,7 @@ class ObservableMap<T> implements IObservableMap<T> {
    * Whether this map has been disposed.
    */
   get isDisposed(): boolean {
-    return this._map === null;
+    return this._isDisposed;
   }
 
   /**
@@ -318,9 +318,10 @@ class ObservableMap<T> implements IObservableMap<T> {
    * Dispose of the resources held by the map.
    */
   dispose(): void {
-    if (this._map === null) {
+    if (this.isDisposed) {
       return;
     }
+    this._isDisposed = true;
     Signal.clearData(this);
     this._map.clear();
   }
@@ -328,6 +329,7 @@ class ObservableMap<T> implements IObservableMap<T> {
   private _map: Map<string, T> = new Map<string, T>();
   private _itemCmp: (first: T, second: T) => boolean;
   private _changed = new Signal<this, IObservableMap.IChangedArgs<T>>(this);
+  private _isDisposed = false;
 }