Procházet zdrojové kódy

Ensure non-undefined values for observables

Steven Silvester před 8 roky
rodič
revize
809590a59e

+ 1 - 12
src/common/observablejson.ts

@@ -92,7 +92,7 @@ class ObservableJSON extends ObservableMap<JSONValue> {
    */
   constructor(options: ObservableJSON.IOptions = {}) {
     super({
-      itemCmp: Private.deepEqual,
+      itemCmp: deepEqual,
       values: options.values
     });
   }
@@ -448,15 +448,4 @@ namespace Private {
         h.div({ className: HOST_CLASS }))
     );
   }
-
-  /**
-   * Compare two objects for JSON equality.
-   */
-  export
-  function deepEqual(a: JSONValue, b: JSONValue): boolean {
-    if (a === void 0 || b === void 0) {
-      return false;
-    }
-    return JSONExt.deepEqual(a, b);
-  }
 }

+ 3 - 0
src/common/observablemap.ts

@@ -144,6 +144,9 @@ class ObservableMap<T> implements IObservableMap<T> {
    */
   set(key: string, value: T): T {
     let oldVal = this._map.get(key);
+    if (value === undefined) {
+      value = null;
+    }
     // Bail if the value does not change.
     let itemCmp = this._itemCmp;
     if (itemCmp(oldVal, value)) {

+ 3 - 0
src/common/observablevector.ts

@@ -354,6 +354,9 @@ class ObservableVector<T> extends Vector<T> implements IObservableVector<T> {
    */
   set(index: number, value: T): void {
     let oldValues = [this.at(index)];
+    if (value === undefined) {
+      value = null;
+    }
     // Bail if the value does not change.
     let itemCmp = this._itemCmp;
     if (itemCmp(oldValues[0], value)) {