« get me outta code hell

compute startIndex dynamically - 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>2022-03-05 21:54:59 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-03-05 21:55:19 -0400
commitc5b42b7883025bb3464b52248567133cd0658959 (patch)
tree9e6e632ad157584a123d35adccccc0a39dcd11d9
parentc235939a92104dd1083f40fc0344d9cca45cfb98 (diff)
compute startIndex dynamically
-rw-r--r--src/data/things.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/data/things.js b/src/data/things.js
index 941ef2f..eb01cc1 100644
--- a/src/data/things.js
+++ b/src/data/things.js
@@ -526,11 +526,6 @@ TrackGroup.propertyDescriptors = {
         }
     },
 
-    startIndex: {
-        flags: {update: true, expose: true},
-        update: {validate: isWholeNumber}
-    },
-
     dateOriginallyReleased: Thing.common.simpleDate(),
 
     tracksByRef: Thing.common.referenceList(Track),
@@ -562,6 +557,17 @@ TrackGroup.propertyDescriptors = {
             )
         }
     },
+
+    startIndex: {
+        flags: {expose: true},
+
+        expose: {
+            dependencies: ['album'],
+            compute: ({ album, [TrackGroup.instance]: trackGroup }) => (album.trackGroups
+                .slice(0, album.trackGroups.indexOf(trackGroup))
+                .reduce((acc, tg) => acc + tg.tracks.length, 0))
+        }
+    },
 };
 
 // -> Track