« get me outta code hell

data: simplify withAlbum, withFlashAct, remove notFoundMode - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/things/track/withContainingTrackSection.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-03 12:58:49 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-04-03 13:44:00 -0300
commit01fca1864f58067ec95590700b5dead24fd2dc73 (patch)
tree1dd214b38f1692b6c6122c8244a328b595f91628 /src/data/composite/things/track/withContainingTrackSection.js
parentc730fce11ed3cd57cca6b5290bb83adeb6100dde (diff)
data: simplify withAlbum, withFlashAct, remove notFoundMode
Diffstat (limited to 'src/data/composite/things/track/withContainingTrackSection.js')
-rw-r--r--src/data/composite/things/track/withContainingTrackSection.js47
1 files changed, 13 insertions, 34 deletions
diff --git a/src/data/composite/things/track/withContainingTrackSection.js b/src/data/composite/things/track/withContainingTrackSection.js
index b2e5f2b..eaac14d 100644
--- a/src/data/composite/things/track/withContainingTrackSection.js
+++ b/src/data/composite/things/track/withContainingTrackSection.js
@@ -1,63 +1,42 @@
 // Gets the track section containing this track from its album's track list.
-// If notFoundMode is set to 'exit', this will early exit if the album can't be
-// found or if none of its trackSections includes the track for some reason.
 
 import {input, templateCompositeFrom} from '#composite';
 import {is} from '#validators';
 
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+
 import withPropertyFromAlbum from './withPropertyFromAlbum.js';
 
 export default templateCompositeFrom({
   annotation: `withContainingTrackSection`,
 
-  inputs: {
-    notFoundMode: input({
-      validate: is('exit', 'null'),
-      defaultValue: 'null',
-    }),
-  },
-
   outputs: ['#trackSection'],
 
   steps: () => [
     withPropertyFromAlbum({
       property: input.value('trackSections'),
-      notFoundMode: input('notFoundMode'),
+    }),
+
+    raiseOutputWithoutDependency({
+      dependency: '#album.trackSections',
+      output: input.value({'#trackSection': null}),
     }),
 
     {
       dependencies: [
         input.myself(),
-        input('notFoundMode'),
         '#album.trackSections',
       ],
 
-      compute(continuation, {
+      compute: (continuation, {
         [input.myself()]: track,
         [input('notFoundMode')]: notFoundMode,
         ['#album.trackSections']: trackSections,
-      }) {
-        if (!trackSections) {
-          return continuation.raiseOutput({
-            ['#trackSection']: null,
-          });
-        }
-
-        const trackSection =
-          trackSections.find(({tracks}) => tracks.includes(track));
-
-        if (trackSection) {
-          return continuation.raiseOutput({
-            ['#trackSection']: trackSection,
-          });
-        } else if (notFoundMode === 'exit') {
-          return continuation.exit(null);
-        } else {
-          return continuation.raiseOutput({
-            ['#trackSection']: null,
-          });
-        }
-      },
+      }) => continuation({
+        ['#trackSection']:
+          trackSections.find(({tracks}) => tracks.includes(track))
+            ?? null,
+      }),
     },
   ],
 });