« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/album.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things/album.js')
-rw-r--r--src/data/things/album.js51
1 files changed, 43 insertions, 8 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 42db1773..cf021080 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -44,6 +44,8 @@ import {
 
 import {
   withFlattenedList,
+  withLengthOfList,
+  withNearbyItemFromList,
   withPropertyFromList,
   withPropertyFromObject,
 } from '#composite/data';
@@ -81,9 +83,6 @@ import {
   wikiData,
 } from '#composite/wiki-properties';
 
-import {withContinueCountingFrom, withStartCountingFrom}
-  from '#composite/things/track-section';
-
 export class Album extends Thing {
   static [Thing.referenceType] = 'album';
   static [Thing.wikiData] = 'albumData';
@@ -1046,11 +1045,41 @@ export class TrackSection extends Thing {
     ],
 
     startCountingFrom: [
-      withStartCountingFrom({
-        from: input.updateValue({validate: isNumber}),
+      exposeUpdateValueOrContinue({
+        validate: input.value(isNumber),
+      }),
+
+      exitWithoutDependency({
+        dependency: 'album',
+        value: input.value(1),
+      }),
+
+      withPropertyFromObject({
+        object: 'album',
+        property: input.value('trackSections'),
+      }),
+
+      withNearbyItemFromList({
+        list: '#album.trackSections',
+        item: input.myself(),
+        offset: input.value(-1),
+      }).outputs({
+        '#nearbyItem': '#previousTrackSection',
+      }),
+
+      exitWithoutDependency({
+        dependency: '#previousTrackSection',
+        value: input.value(1),
+      }),
+
+      withPropertyFromObject({
+        object: '#previousTrackSection',
+        property: input.value('continueCountingFrom'),
       }),
 
-      exposeDependency({dependency: '#startCountingFrom'}),
+      exposeDependency({
+        dependency: '#previousTrackSection.continueCountingFrom',
+      }),
     ],
 
     dateOriginallyReleased: simpleDate(),
@@ -1115,9 +1144,15 @@ export class TrackSection extends Thing {
     ],
 
     continueCountingFrom: [
-      withContinueCountingFrom(),
+      withLengthOfList({
+        list: 'tracks',
+      }),
 
-      exposeDependency({dependency: '#continueCountingFrom'}),
+      {
+        dependencies: ['startCountingFrom', '#tracks.length'],
+        compute: ({startCountingFrom, '#tracks.length': tracks}) =>
+          startCountingFrom + tracks,
+      },
     ],
   });