Browse Source

Bug fix: observable map was losing lossy values.

Afshin Darian 7 years ago
parent
commit
4566eb505c
1 changed files with 8 additions and 10 deletions
  1. 8 10
      packages/coreutils/src/observablejson.ts

+ 8 - 10
packages/coreutils/src/observablejson.ts

@@ -58,16 +58,14 @@ class ObservableJSON extends ObservableMap<JSONValue> {
    * Serialize the model to JSON.
    */
   toJSON(): JSONObject {
-    let out: JSONObject = Object.create(null);
-    for (let key of this.keys()) {
-      let value = this.get(key);
-      if (!value) {
-        continue;
-      }
-      if (JSONExt.isPrimitive(value)) {
-        out[key] = value;
-      } else {
-        out[key] = JSON.parse(JSON.stringify(value));
+    const out: JSONObject = Object.create(null);
+    const keys = this.keys();
+
+    for (let key of keys) {
+      const value = this.get(key);
+
+      if (value !== undefined) {
+        out[key] = JSONExt.isPrimitive(value) ? value : JSONExt.deepCopy(value);
       }
     }
     return out;