« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/data/checks.js11
-rw-r--r--src/data/composite/things/track/withMainRelease.js41
-rw-r--r--src/data/things/album.js18
3 files changed, 66 insertions, 4 deletions
diff --git a/src/data/checks.js b/src/data/checks.js
index 5688b979..b7a237ad 100644
--- a/src/data/checks.js
+++ b/src/data/checks.js
@@ -350,6 +350,17 @@ export function filterReferenceErrors(wikiData, {
                 findFn = ref => {
                   // Mocking what's going on in `withMainRelease`.
 
+                  if (ref === 'same name single') {
+                    // Accessing the current thing here.
+                    try {
+                      return boundFind.albumSinglesOnly(thing.name);
+                    } catch (caughtError) {
+                      throw new Error(
+                        `Didn't match a single with the same name`,
+                        {cause: caughtError});
+                    }
+                  }
+
                   let track, trackError;
                   let album, albumError;
 
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',
diff --git a/src/data/things/album.js b/src/data/things/album.js
index ac947cfa..2817d78d 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -510,6 +510,20 @@ export class Album extends Thing {
           : [album.name]),
     },
 
+    albumSinglesOnly: {
+      referencing: ['album'],
+
+      bindTo: 'albumData',
+
+      incldue: album =>
+        album.style === 'single',
+
+      getMatchableNames: album =>
+        (album.alwaysReferenceByDirectory
+          ? []
+          : [album.name]),
+    },
+
     albumWithArtwork: {
       referenceTypes: [
         'album',
@@ -523,8 +537,8 @@ export class Album extends Thing {
         album.hasCoverArt,
 
       getMatchableNames: album =>
-        (album.alwaysReferenceByDirectory 
-          ? [] 
+        (album.alwaysReferenceByDirectory
+          ? []
           : [album.name]),
     },