« get me outta code hell

data, test: update & test misc. Track reverse reference lists - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/thing.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-31 19:52:42 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-05 21:02:56 -0300
commit6325a70991396412eb8e93cee5f17bdb2859ae9d (patch)
tree3efd9feef5da0707cb08cc86ea1b5715f8fbc271 /src/data/things/thing.js
parent6f54b1211b5b07fe747ce4ebafdf917ce7851324 (diff)
data, test: update & test misc. Track reverse reference lists
* update & test Track.referencedByTracks
* update & test Track.sampledByTracks
* update & test Track.featuredInFlashes

* update Thing.common.reverseReferenceList
* add Thing.composite.withReverseReferenceList
* add Track.composite.trackReverseReferenceList
Diffstat (limited to 'src/data/things/thing.js')
-rw-r--r--src/data/things/thing.js43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 15ec62c3..1c99a323 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -330,16 +330,15 @@ export default class Thing extends CacheableObject {
     // you would use this to compute a corresponding "referenced *by* tracks"
     // property. Naturally, the passed ref list property is of the things in the
     // wiki data provided, not the requesting Thing itself.
-    reverseReferenceList: (thingDataProperty, referencerRefListProperty) => ({
-      flags: {expose: true},
-
-      expose: {
-        dependencies: ['this', thingDataProperty],
-
-        compute: ({this: thing, [thingDataProperty]: thingData}) =>
-          thingData?.filter(t => t[referencerRefListProperty].includes(thing)) ?? [],
-      },
-    }),
+    reverseReferenceList({
+      data,
+      refList,
+    }) {
+      return Thing.composite.from(`Thing.common.reverseReferenceList`, [
+        Thing.composite.withReverseReferenceList({data, refList}),
+        Thing.composite.exposeDependency('#reverseReferenceList'),
+      ]);
+    },
 
     // Corresponding function for single references. Note that the return value
     // is still a list - this is for matching all the objects whose single
@@ -1535,5 +1534,29 @@ export default class Thing extends CacheableObject {
         },
       ]);
     },
+
+    // Check out the info on Thing.common.reverseReferenceList!
+    // This is its composable form.
+    withReverseReferenceList({
+      data,
+      to = '#reverseReferenceList',
+      refList: refListProperty,
+    }) {
+      return Thing.composite.from(`Thing.common.reverseReferenceList`, [
+        Thing.composite.earlyExitWithoutDependency(data, {value: []}),
+
+        {
+          dependencies: ['this'],
+          mapDependencies: {data},
+          mapContinuation: {to},
+          options: {refListProperty},
+
+          compute: ({this: thisThing, data, '#options': {refListProperty}}, continuation) =>
+            continuation({
+              to: data.filter(thing => thing[refListProperty].includes(thisThing)),
+            }),
+        },
+      ]);
+    },
   };
 }