Browse Source

wip strict null cleanup

Steven Silvester 7 years ago
parent
commit
2190c45786
2 changed files with 11 additions and 15 deletions
  1. 10 5
      packages/coreutils/src/statedb.ts
  2. 1 10
      packages/coreutils/src/undoablelist.ts

+ 10 - 5
packages/coreutils/src/statedb.ts

@@ -113,7 +113,7 @@ class StateDB implements IStateDB {
     let i = window.localStorage.length;
     while (i) {
       let key = window.localStorage.key(--i);
-      if (key.indexOf(prefix) === 0) {
+      if (key && key.indexOf(prefix) === 0) {
         window.localStorage.removeItem(key);
       }
     }
@@ -137,10 +137,14 @@ class StateDB implements IStateDB {
    * The promise returned by this method may be rejected if an error occurs in
    * retrieving the data. Non-existence of an `id` will succeed with `null`.
    */
-  fetch(id: string): Promise<JSONObject | null> {
+  fetch(id: string): Promise<JSONObject | undefined> {
     const key = `${this.namespace}:${id}`;
+    const value = window.localStorage.getItem(key);
+    if (!value) {
+      return Promise.resolve(undefined);
+    }
     try {
-      return Promise.resolve(JSON.parse(window.localStorage.getItem(key)));
+      return Promise.resolve(JSON.parse(value));
     } catch (error) {
       return Promise.reject(error);
     }
@@ -169,11 +173,12 @@ class StateDB implements IStateDB {
     let i = window.localStorage.length;
     while (i) {
       let key = window.localStorage.key(--i);
-      if (key.indexOf(prefix) === 0) {
+      if (key && key.indexOf(prefix) === 0) {
+        let value = window.localStorage.getItem(key);
         try {
           items.push({
             id: key.replace(regex, ''),
-            value: JSON.parse(window.localStorage.getItem(key))
+            value: value ? JSON.parse(value) : undefined
           });
         } catch (error) {
           console.warn(error);

+ 1 - 10
packages/coreutils/src/undoablelist.ts

@@ -105,15 +105,6 @@ class ObservableUndoableList<T> extends ObservableList<T> implements IObservable
     return this._index >= 0;
   }
 
-  /**
-   * Dispose of the resources held by the model.
-   */
-  dispose(): void {
-    this._serializer = null;
-    this._stack = null;
-    super.dispose();
-  }
-
   /**
    * Begin a compound operation.
    *
@@ -294,7 +285,7 @@ class ObservableUndoableList<T> extends ObservableList<T> implements IObservable
   private _madeCompoundChange = false;
   private _index = -1;
   private _stack: IObservableList.IChangedArgs<JSONValue>[][] = [];
-  private _serializer: ISerializer<T> = null;
+  private _serializer: ISerializer<T>;
 }
 
 /**