« get me outta code hell

data: withPropertyFrom{Object,List}, fillMissingListItems utils - 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:
author(quasar) nebula <qznebula@protonmail.com>2023-09-09 08:13:44 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-09 08:14:11 -0300
commitc82784ebb4e5141bfe97664f3252303b3e833863 (patch)
tree5f4dfa5d990ca83d5eec71faccb95d84935a870a /src/data/things/album.js
parent6fe22802d8220b983a488f4efee1834bacbdb166 (diff)
data: withPropertyFrom{Object,List}, fillMissingListItems utils
Diffstat (limited to 'src/data/things/album.js')
-rw-r--r--src/data/things/album.js66
1 files changed, 27 insertions, 39 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 5e281f0..288caa0 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -8,8 +8,11 @@ import {
   exitWithoutUpdateValue,
   exposeDependency,
   exposeUpdateValueOrContinue,
+  fillMissingListItems,
   withFlattenedArray,
+  withPropertyFromList,
   withUnflattenedArray,
+  withUpdateValueAsDependency,
 } from '#composite';
 
 import Thing, {
@@ -81,50 +84,35 @@ export class Album extends Thing {
       exitWithoutDependency({dependency: 'trackData', value: []}),
       exitWithoutUpdateValue({value: [], mode: 'empty'}),
 
-      {
-        transform: (trackSections, continuation) =>
-          continuation(trackSections, {
-            '#sectionTrackRefs':
-              trackSections.map(section => section.tracks),
-
-            '#sectionDateOriginallyReleased':
-              trackSections
-                .map(({dateOriginallyReleased}) => dateOriginallyReleased ?? null),
-
-            '#sectionIsDefaultTrackSection':
-              trackSections
-                .map(({isDefaultTrackSection}) => isDefaultTrackSection ?? false),
-          }),
-      },
+      withUpdateValueAsDependency({into: '#sections'}),
 
-      {
-        dependencies: ['color'],
-        transform: (trackSections, {color: albumColor}, continuation) =>
-          continuation(trackSections, {
-            '#sectionColor':
-              trackSections
-                .map(({color: sectionColor}) => sectionColor ?? albumColor),
-          }),
-      },
+      withPropertyFromList({list: '#sections', property: 'tracks', into: '#sections.trackRefs'}),
+      withPropertyFromList({list: '#sections', property: 'dateOriginallyReleased'}),
+      withPropertyFromList({list: '#sections', property: 'isDefaultTrackSection'}),
+      withPropertyFromList({list: '#sections', property: 'color'}),
+
+      fillMissingListItems({list: '#sections.trackRefs', value: []}),
+      fillMissingListItems({list: '#sections.isDefaultTrackSection', value: false}),
+      fillMissingListItems({list: '#sections.color', dependency: 'color'}),
 
       withFlattenedArray({
-        from: '#sectionTrackRefs',
+        from: '#sections.trackRefs',
         into: '#trackRefs',
-        intoIndices: '#sectionStartIndex',
+        intoIndices: '#sections.startIndex',
       }),
 
       withResolvedReferenceList({
         list: '#trackRefs',
         data: 'trackData',
-        mode: 'null',
+        notFoundMode: 'null',
         find: find.track,
         into: '#tracks',
       }),
 
       withUnflattenedArray({
         from: '#tracks',
-        fromIndices: '#sectionStartIndex',
-        into: '#sectionTracks',
+        fromIndices: '#sections.startIndex',
+        into: '#sections.tracks',
       }),
 
       {
@@ -134,19 +122,19 @@ export class Album extends Thing {
 
         expose: {
           dependencies: [
-            '#sectionTracks',
-            '#sectionColor',
-            '#sectionDateOriginallyReleased',
-            '#sectionIsDefaultTrackSection',
-            '#sectionStartIndex',
+            '#sections.tracks',
+            '#sections.color',
+            '#sections.dateOriginallyReleased',
+            '#sections.isDefaultTrackSection',
+            '#sections.startIndex',
           ],
 
           transform: (trackSections, {
-            '#sectionTracks': tracks,
-            '#sectionColor': color,
-            '#sectionDateOriginallyReleased': dateOriginallyReleased,
-            '#sectionIsDefaultTrackSection': isDefaultTrackSection,
-            '#sectionStartIndex': startIndex,
+            '#sections.tracks': tracks,
+            '#sections.color': color,
+            '#sections.dateOriginallyReleased': dateOriginallyReleased,
+            '#sections.isDefaultTrackSection': isDefaultTrackSection,
+            '#sections.startIndex': startIndex,
           }) =>
             stitchArrays({
               tracks,