« get me outta code hell

data: filter only requested deps, require requesting 'this' - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-22 13:02:19 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-05 21:02:49 -0300
commit75691866ed68b9261dd920b79d4ab214df3f049b (patch)
tree0a8d328279498631bdab9eaa2afedcee5574c7fb /src/util
parent93448ef747b681d3b87b050b555311c0172b83cc (diff)
data: filter only requested deps, require requesting 'this'
* Thing.composite.from() only provides the dependencies specified
  in each step and the base, and prevents '#'-prefixed keys from
  being specified on the main (composite) dependency list.

* CacheableObject no longer provides a "reflection" dependency to
  every compute/transform function, and now requires the property
  'this' to be specified instead of the constructor.instance
  symbol. (The static CacheableObject.instance, inherited by all
  subclasses, was also removed.)

* Also minor improvements to sugar.js data processing utility
  functions.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sugar.js24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index 5b1f319..1ba3f3a 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -168,12 +168,24 @@ export function setIntersection(set1, set2) {
   return intersection;
 }
 
-export function filterProperties(obj, properties) {
-  const set = new Set(properties);
-  return Object.fromEntries(
-    Object
-      .entries(obj)
-      .filter(([key]) => set.has(key)));
+export function filterProperties(object, properties) {
+  if (typeof object !== 'object' || object === null) {
+    throw new TypeError(`Expected object to be an object, got ${object}`);
+  }
+
+  if (!Array.isArray(properties)) {
+    throw new TypeError(`Expected properties to be an array, got ${properties}`);
+  }
+
+  const filteredObject = {};
+
+  for (const property of properties) {
+    if (Object.hasOwn(object, property)) {
+      filteredObject[property] = object[property];
+    }
+  }
+
+  return filteredObject;
 }
 
 export function queue(array, max = 50) {