« get me outta code hell

data: Track.withAlbum: bulkily match documented early exit behavior - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-10-26 18:03:24 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-10-26 19:36:58 -0300
commitc7e21005beb8807216aac6ed3ae54029575007a1 (patch)
tree226a761e9993136313cdb4ac57e3170920c5b386 /src
parentbdad6e4abd6c456a65e30b93247964fdd9a1f48c (diff)
data: Track.withAlbum: bulkily match documented early exit behavior
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/things/track/withAlbum.js45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/data/composite/things/track/withAlbum.js b/src/data/composite/things/track/withAlbum.js
index 34845ab0..0e85cee9 100644
--- a/src/data/composite/things/track/withAlbum.js
+++ b/src/data/composite/things/track/withAlbum.js
@@ -4,10 +4,9 @@
 // exit instead.
 
 import {input, templateCompositeFrom} from '#composite';
+import {empty} from '#sugar';
 import {is} from '#validators';
 
-import {raiseOutputWithoutDependency} from '#composite/control-flow';
-
 export default templateCompositeFrom({
   annotation: `withAlbum`,
 
@@ -21,13 +20,20 @@ export default templateCompositeFrom({
   outputs: ['#album'],
 
   steps: () => [
-    raiseOutputWithoutDependency({
-      dependency: 'albumData',
-      mode: input.value('empty'),
-      output: input.value({
-        ['#album']: null,
-      }),
-    }),
+    {
+      dependencies: [input('notFoundMode'), 'albumData'],
+      compute: (continuation, {
+        [input('notFoundMode')]: notFoundMode,
+        ['albumData']: albumData,
+      }) =>
+        (albumData === null
+          ? continuation.exit(null)
+       : empty(albumData)
+          ? (notFoundMode === 'exit'
+              ? continuation.exit(null)
+              : continuation.raiseOutput({'#album': null}))
+          : continuation()),
+    },
 
     {
       dependencies: [input.myself(), 'albumData'],
@@ -37,21 +43,20 @@ export default templateCompositeFrom({
       }) =>
         continuation({
           ['#album']:
-            albumData.find(album => album.tracks.includes(track)),
+            albumData.find(album => album.tracks.includes(track))
+              ?? null,
         }),
     },
 
-    raiseOutputWithoutDependency({
-      dependency: '#album',
-      output: input.value({
-        ['#album']: null,
-      }),
-    }),
-
     {
-      dependencies: ['#album'],
-      compute: (continuation, {'#album': album}) =>
-        continuation.raiseOutput({'#album': album}),
+      dependencies: [input('notFoundMode'), '#album'],
+      compute: (continuation, {
+        [input('notFoundMode')]: notFoundMode,
+        ['#album']: album,
+      }) =>
+        ((album === null && notFoundMode === 'exit')
+          ? continuation.exit(null)
+          : continuation.raiseOutput({'#album': album})),
     },
   ],
 });