« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/thing/album.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/thing/album.js')
-rw-r--r--src/thing/album.js42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/thing/album.js b/src/thing/album.js
index 8a9fde2c..426796b0 100644
--- a/src/thing/album.js
+++ b/src/thing/album.js
@@ -1,6 +1,5 @@
 import CacheableObject from './cacheable-object.js';
 import Thing from './thing.js';
-import find from '../util/find.js';
 
 import {
     isBoolean,
@@ -10,6 +9,7 @@ import {
     isDate,
     isDimensions,
     isDirectory,
+    isInstance,
     isFileExtension,
     isName,
     isURL,
@@ -20,6 +20,10 @@ import {
     validateReferenceList,
 } from './validators.js';
 
+import Track from './track.js';
+
+import find from '../util/find.js';
+
 export class TrackGroup extends CacheableObject {
     static propertyDescriptors = {
         // Update & expose
@@ -64,7 +68,12 @@ export class TrackGroup extends CacheableObject {
             expose: {
                 dependencies: ['tracksByRef', 'trackData'],
                 compute: ({ tracksByRef, trackData }) => (
-                    tracksByRef.map(ref => find.track(ref, {wikiData: {trackData}})))
+                    (tracksByRef && trackData
+                        ? (tracksByRef
+                            .map(ref => find.track(ref, {wikiData: {trackData}}))
+                            .filter(Boolean))
+                        : [])
+                )
             }
         }
     };
@@ -227,26 +236,29 @@ export default class Album extends Thing {
             update: {validate: isCommentary}
         },
 
+        // Update only
+
+        trackData: {
+            flags: {update: true},
+            update: {validate: validateArrayItems(x => x instanceof Track)}
+        },
+
         // Expose only
 
-        /*
         tracks: {
             flags: {expose: true},
 
             expose: {
-                dependencies: ['trackReferences', 'wikiData'],
-                compute: ({trackReferences, wikiData}) => (
-                    trackReferences.map(ref => find.track(ref, {wikiData})))
+                dependencies: ['trackGroups', 'trackData'],
+                compute: ({ trackGroups, trackData }) => (
+                    (trackGroups && trackData
+                        ? (trackGroups
+                            .flatMap(group => group.tracksByRef ?? [])
+                            .map(ref => find.track(ref, {wikiData: {trackData}}))
+                            .filter(Boolean))
+                        : [])
+                )
             }
         },
-        */
-
-        // Update only
-
-        /*
-        wikiData: {
-            flags: {update: true}
-        }
-        */
     };
 }