« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/data/things/album.js33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 3726a463..76e0f638 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -26,6 +26,7 @@ import Thing, {
   urls,
   wikiData,
   withResolvedContribs,
+  withResolvedReferenceList,
 } from './thing.js';
 
 export class Album extends Thing {
@@ -147,20 +148,30 @@ export class Album extends Thing {
     hasWallpaperArt: contribsPresent('wallpaperArtistContribs'),
     hasBannerArt: contribsPresent('bannerArtistContribs'),
 
-    tracks: {
-      flags: {expose: true},
+    tracks: compositeFrom(`Album.tracks`, [
+      exitWithoutDependency({
+        dependency: 'trackSections',
+        mode: 'empty',
+        value: [],
+      }),
 
-      expose: {
+      {
         dependencies: ['trackSections', 'trackData'],
-        compute: ({trackSections, trackData}) =>
-          (trackSections && trackData
-            ? trackSections
-                .flatMap(section => section.tracks ?? [])
-                .map(ref => find.track(ref, trackData, {mode: 'quiet'}))
-                .filter(Boolean)
-            : []),
+        compute: ({trackSections, trackData}, continuation) =>
+          continuation({
+            '#trackRefs': trackSections
+              .flatMap(section => section.tracks ?? []),
+          }),
       },
-    },
+
+      withResolvedReferenceList({
+        list: '#trackRefs',
+        data: 'trackData',
+        find: find.track,
+      }),
+
+      exposeDependency({dependency: '#resolvedReferenceList'}),
+    ]),
   });
 
   static [Thing.getSerializeDescriptors] = ({