« get me outta code hell

cacheable-object: clone, copyUpdateValuesOnto - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-06 13:35:56 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-12 17:26:34 -0300
commit06303dc8585add99110160a69c6d9c818a9b5ded (patch)
tree9f5516ba5da0d216283acb3c43bc37ee24c4d37f /src/data
parentd5e79dc9330ad5a52503b27e4b6688239a97c2ac (diff)
cacheable-object: clone, copyUpdateValuesOnto
Diffstat (limited to 'src/data')
-rw-r--r--src/data/cacheable-object.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/data/cacheable-object.js b/src/data/cacheable-object.js
index 71dc5bde..010d967a 100644
--- a/src/data/cacheable-object.js
+++ b/src/data/cacheable-object.js
@@ -374,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 {