« get me outta code hell

data: update Thing.common.dynamicThingsFromReferenceList - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-31 15:57:15 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-05 21:02:55 -0300
commit5a63b96cfd3d26e4b74ff4c6dfc793aef057f81b (patch)
treeb3e562e07e4e70182e373a4a00bb676217db2123
parent918fb043a640cf937de604fc74cb95566fa66459 (diff)
data: update Thing.common.dynamicThingsFromReferenceList
Only the internal implementation. This should really be updated to
take key/value-style parameters, and probably be renamed, but this
helps to confirm a swathe of expected behavior continues to work
with an existing `common` utility reimplemented compositionally.
-rw-r--r--src/data/things/thing.js41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 389b3845..751e168f 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -192,26 +192,29 @@ export default class Thing extends CacheableObject {
     // Corresponding dynamic property to referenceList, which takes the values
     // in the provided property and searches the specified wiki data for
     // matching actual Thing-subclass objects.
-    dynamicThingsFromReferenceList: (
-      referenceListProperty,
-      thingDataProperty,
-      findFn
-    ) => ({
-      flags: {expose: true},
+    dynamicThingsFromReferenceList(
+      refs,
+      data,
+      findFunction
+    ) {
+      return Thing.composite.from(`Thing.common.dynamicThingsFromReferenceList`, [
+        Thing.composite.earlyExitWithoutDependency(refs, {value: []}),
+        Thing.composite.earlyExitWithoutDependency(data, {value: []}),
 
-      expose: {
-        dependencies: [referenceListProperty, thingDataProperty],
-        compute: ({
-          [referenceListProperty]: refs,
-          [thingDataProperty]: thingData,
-        }) =>
-          refs && thingData
-            ? refs
-                .map((ref) => findFn(ref, thingData, {mode: 'quiet'}))
-                .filter(Boolean)
-            : [],
-      },
-    }),
+        {
+          flags: {expose: true},
+          expose: {
+            mapDependencies: {refs, data},
+            options: {findFunction},
+
+            compute: ({refs, data, '#options': {findFunction}}) =>
+              refs
+                .map(ref => findFunction(ref, data, {mode: 'quiet'}))
+                .filter(Boolean),
+          },
+        },
+      ]);
+    },
 
     // Corresponding function for a single reference.
     dynamicThingFromSingleReference: (