From c5b42b7883025bb3464b52248567133cd0658959 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 5 Mar 2022 21:54:59 -0400 Subject: compute startIndex dynamically --- src/data/things.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/data/things.js b/src/data/things.js index 941ef2f2..eb01cc16 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 -- cgit 1.3.0-6-gf8a5