« 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/composite/things
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/composite/things')
-rw-r--r--src/data/composite/things/track/withMainRelease.js41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/data/composite/things/track/withMainRelease.js b/src/data/composite/things/track/withMainRelease.js
index b1f427eb..f1b0841a 100644
--- a/src/data/composite/things/track/withMainRelease.js
+++ b/src/data/composite/things/track/withMainRelease.js
@@ -33,20 +33,57 @@ export default templateCompositeFrom({
       output: input.value({'#mainRelease': null}),
     }),
 
+    {
+      dependencies: [input('from'), 'name'],
+      compute: (continuation, {
+        [input('from')]: ref,
+        ['name']: ownName,
+      }) =>
+        (ref === 'same name single'
+          ? continuation({
+              ['#albumOrTrackReference']: null,
+              ['#sameNameSingleReference']: ownName,
+            })
+          : continuation({
+              ['#albumOrTrackReference']: ref,
+              ['#sameNameSingleReference']: null,
+            })),
+    },
+
     withResolvedReference({
-      ref: input('from'),
+      ref: '#albumOrTrackReference',
       find: soupyFind.input('trackMainReleasesOnly'),
     }).outputs({
       '#resolvedReference': '#matchingTrack',
     }),
 
     withResolvedReference({
-      ref: input('from'),
+      ref: '#albumOrTrackReference',
       find: soupyFind.input('album'),
     }).outputs({
       '#resolvedReference': '#matchingAlbum',
     }),
 
+    withResolvedReference({
+      ref: '#sameNameSingleReference',
+      find: soupyFind.input('albumSinglesOnly'),
+    }).outputs({
+      '#resolvedReference': '#sameNameSingle',
+    }),
+
+    {
+      dependencies: ['#sameNameSingle'],
+      compute: (continuation, {
+        ['#sameNameSingle']: sameNameSingle,
+      }) =>
+        (sameNameSingle
+          ? continuation.raiseOutput({
+              ['#mainRelease']:
+                sameNameSingle,
+            })
+          : continuation()),
+    },
+
     {
       dependencies: [
         '#matchingTrack',