« 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
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
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')
-rw-r--r--src/data/things/thing.js43
-rw-r--r--src/data/things/track.js54
2 files changed, 58 insertions, 39 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)),
+            }),
+        },
+      ]);
+    },
   };
 }
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 0b34de20..bc9affbe 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -278,38 +278,15 @@ export class Track extends Thing {
     // counting the number of times a track has been referenced, for use in
     // the "Tracks - by Times Referenced" listing page (or other data
     // processing).
-    referencedByTracks: {
-      flags: {expose: true},
-
-      expose: {
-        dependencies: ['this', 'trackData'],
-
-        compute: ({this: track, trackData}) =>
-          trackData
-            ? trackData
-                .filter((t) => !t.originalReleaseTrack)
-                .filter((t) => t.referencedTracks?.includes(track))
-            : [],
-      },
-    },
+    referencedByTracks: Track.composite.trackReverseReferenceList('referencedTracks'),
 
     // For the same reasoning, exclude re-releases from sampled tracks too.
-    sampledByTracks: {
-      flags: {expose: true},
-
-      expose: {
-        dependencies: ['this', 'trackData'],
-
-        compute: ({this: track, trackData}) =>
-          trackData
-            ? trackData
-                .filter((t) => !t.originalReleaseTrack)
-                .filter((t) => t.sampledTracks?.includes(track))
-            : [],
-      },
-    },
+    sampledByTracks: Track.composite.trackReverseReferenceList('sampledTracks'),
 
-    featuredInFlashes: Thing.common.reverseReferenceList('flashData', 'featuredTracks'),
+    featuredInFlashes: Thing.common.reverseReferenceList({
+      data: 'flashData',
+      refList: 'featuredTracks',
+    }),
   });
 
   static composite = {
@@ -575,6 +552,25 @@ export class Track extends Thing {
         },
       ]);
     },
+
+    trackReverseReferenceList(refListProperty) {
+      return Thing.composite.from(`Track.composite.trackReverseReferenceList`, [
+        Thing.composite.withReverseReferenceList({
+          data: 'trackData',
+          refList: refListProperty,
+          originalTracksOnly: true,
+        }),
+
+        {
+          flags: {expose: true},
+          expose: {
+            dependencies: ['#reverseReferenceList'],
+            compute: ({'#reverseReferenceList': reverseReferenceList}) =>
+              reverseReferenceList.filter(track => !track.originalReleaseTrack),
+          },
+        },
+      ]);
+    },
   };
 
   [inspect.custom](depth) {