« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/cacheable-object.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/cacheable-object.js')
-rw-r--r--src/data/cacheable-object.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/data/cacheable-object.js b/src/data/cacheable-object.js
index 4a89b774..010d967a 100644
--- a/src/data/cacheable-object.js
+++ b/src/data/cacheable-object.js
@@ -132,7 +132,11 @@ export default class CacheableObject {
         return;
       }
 
-      if ('default' in update) {
+      if (
+        typeof update === 'object' &&
+        update !== null &&
+        'default' in update
+      ) {
         this[property] = update?.default;
       } else {
         this[property] = null;
@@ -370,6 +374,18 @@ export default class CacheableObject {
 
     return object.#propertyUpdateValues[key] ?? null;
   }
+
+  static clone(object) {
+    const newObject = Reflect.construct(object.constructor, []);
+
+    this.copyUpdateValuesOnto(object, newObject);
+
+    return newObject;
+  }
+
+  static copyUpdateValuesOnto(source, target) {
+    Object.assign(target, source.#propertyUpdateValues);
+  }
 }
 
 export class CacheableObjectPropertyValueError extends Error {