« 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/things/track.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things/track.js')
-rw-r--r--src/data/things/track.js64
1 files changed, 38 insertions, 26 deletions
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 87eca2e9..110769e0 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -12,6 +12,7 @@ import {
   isContributionList,
   isDate,
   isFileExtension,
+  validateReference,
 } from '#validators';
 
 import {
@@ -60,7 +61,6 @@ import {
   reverseReferenceList,
   simpleDate,
   simpleString,
-  singleReference,
   soupyFind,
   soupyReverse,
   thing,
@@ -70,17 +70,18 @@ import {
 } from '#composite/wiki-properties';
 
 import {
+  alwaysReferenceByDirectory,
   exitWithoutUniqueCoverArt,
   inheritContributionListFromMainRelease,
   inheritFromMainRelease,
   withAllReleases,
-  withAlwaysReferenceByDirectory,
   withContainingTrackSection,
   withCoverArtistContribs,
   withDate,
   withDirectorySuffix,
   withHasUniqueCoverArt,
   withMainRelease,
+  withMainReleaseTrack,
   withOtherReleases,
   withPropertyFromAlbum,
   withSuffixDirectoryFromAlbum,
@@ -143,15 +144,23 @@ export class Track extends Thing {
       })
     ],
 
-    alwaysReferenceByDirectory: [
-      withAlwaysReferenceByDirectory(),
-      exposeDependency({dependency: '#alwaysReferenceByDirectory'}),
-    ],
+    alwaysReferenceByDirectory: alwaysReferenceByDirectory(),
 
-    mainReleaseTrack: singleReference({
-      class: input.value(Track),
-      find: soupyFind.input('track'),
-    }),
+    // Album or track. The exposed value is really just what's provided here,
+    // whether or not a matching track is found on a provided album, for
+    // example. When presenting or processing, read `mainReleaseTrack`.
+    mainRelease: [
+      withMainRelease({
+        from: input.updateValue({
+          validate:
+            validateReference(['album', 'track']),
+        }),
+      }),
+
+      exposeDependency({
+        dependency: '#mainRelease',
+      }),
+    ],
 
     bandcampTrackIdentifier: simpleString(),
     bandcampArtworkIdentifier: simpleString(),
@@ -453,11 +462,6 @@ export class Track extends Thing {
       class: input.value(Artwork),
     }),
 
-    // used for withAlwaysReferenceByDirectory (for some reason)
-    trackData: wikiData({
-      class: input.value(Track),
-    }),
-
     // used for withMatchingContributionPresets (indirectly by Contribution)
     wikiInfo: thing({
       class: input.value(WikiInfo),
@@ -489,19 +493,27 @@ export class Track extends Thing {
     ],
 
     isMainRelease: [
-      withMainRelease(),
+      withMainReleaseTrack(),
 
       exposeWhetherDependencyAvailable({
-        dependency: '#mainRelease',
+        dependency: '#mainReleaseTrack',
         negate: input.value(true),
       }),
     ],
 
     isSecondaryRelease: [
-      withMainRelease(),
+      withMainReleaseTrack(),
 
       exposeWhetherDependencyAvailable({
-        dependency: '#mainRelease',
+        dependency: '#mainReleaseTrack',
+      }),
+    ],
+
+    mainReleaseTrack: [
+      withMainReleaseTrack(),
+
+      exposeDependency({
+        dependency: '#mainReleaseTrack',
       }),
     ],
 
@@ -522,20 +534,20 @@ export class Track extends Thing {
     ],
 
     commentaryFromMainRelease: [
-      withMainRelease(),
+      withMainReleaseTrack(),
 
       exitWithoutDependency({
-        dependency: '#mainRelease',
+        dependency: '#mainReleaseTrack',
         value: input.value([]),
       }),
 
       withPropertyFromObject({
-        object: '#mainRelease',
+        object: '#mainReleaseTrack',
         property: input.value('commentary'),
       }),
 
       exposeDependency({
-        dependency: '#mainRelease.commentary',
+        dependency: '#mainReleaseTrack.commentary',
       }),
     ],
 
@@ -570,7 +582,7 @@ export class Track extends Thing {
       'Directory': {property: 'directory'},
       'Suffix Directory': {property: 'suffixDirectoryFromAlbum'},
       'Always Reference By Directory': {property: 'alwaysReferenceByDirectory'},
-      'Main Release': {property: 'mainReleaseTrack'},
+      'Main Release': {property: 'mainRelease'},
 
       'Bandcamp Track ID': {
         property: 'bandcampTrackIdentifier',
@@ -797,7 +809,7 @@ export class Track extends Thing {
       bindTo: 'trackData',
 
       include: track =>
-        !CacheableObject.getUpdateValue(track, 'mainReleaseTrack'),
+        !CacheableObject.getUpdateValue(track, 'mainRelease'),
 
       // It's still necessary to check alwaysReferenceByDirectory here, since
       // it may be set manually (with `Always Reference By Directory: true`),
@@ -956,7 +968,7 @@ export class Track extends Thing {
 
     parts.push(Thing.prototype[inspect.custom].apply(this));
 
-    if (CacheableObject.getUpdateValue(this, 'mainReleaseTrack')) {
+    if (CacheableObject.getUpdateValue(this, 'mainRelease')) {
       parts.unshift(`${colors.yellow('[secrelease]')} `);
     }