« get me outta code hell

data: clean up some track property implementations - 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:
author(quasar) nebula <qznebula@protonmail.com>2023-09-09 09:01:09 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-09 09:01:09 -0300
commitceaed5fef3ce2c5d59a6606a6318164b93294f2b (patch)
tree03c83287c156a48063f3f03d9db8f28a9935b9cf /src/data/things/track.js
parent7a21c665d888b0db4c47c72049f7649bf1dabcde (diff)
data: clean up some track property implementations
Diffstat (limited to 'src/data/things/track.js')
-rw-r--r--src/data/things/track.js47
1 files changed, 20 insertions, 27 deletions
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 5e553b4..25d316e 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -61,22 +61,12 @@ export class Track extends Thing {
 
     color: compositeFrom(`Track.color`, [
       exposeUpdateValueOrContinue(),
-      withContainingTrackSection(),
 
-      {
-        dependencies: ['#trackSection'],
-        compute: ({'#trackSection': trackSection}, continuation) =>
-          // Album.trackSections guarantees the track section will have a
-          // color property (inheriting from the album's own color), but only
-          // if it's actually present! Color will be inherited directly from
-          // album otherwise.
-          (trackSection
-            ? trackSection.color
-            : continuation()),
-      },
+      withContainingTrackSection(),
+      withPropertyFromObject({object: '#trackSection', property: 'color'}),
+      exposeDependencyOrContinue({dependency: '#trackSection.color'}),
 
       withPropertyFromAlbum({property: 'color'}),
-
       exposeDependency({
         dependency: '#album.color',
         update: {validate: isColor},
@@ -94,19 +84,13 @@ export class Track extends Thing {
     // of the album's main artwork. It does inherit trackCoverArtFileExtension,
     // if present on the album.
     coverArtFileExtension: compositeFrom(`Track.coverArtFileExtension`, [
-      // No cover art file extension if the track doesn't have unique artwork
-      // in the first place.
-      withHasUniqueCoverArt(),
-      exitWithoutDependency({dependency: '#hasUniqueCoverArt', mode: 'falsy'}),
+      exitWithoutUniqueCoverArt(),
 
-      // Expose custom coverArtFileExtension update value first.
       exposeUpdateValueOrContinue(),
 
-      // Expose album's trackCoverArtFileExtension if no update value set.
       withPropertyFromAlbum({property: 'trackCoverArtFileExtension'}),
       exposeDependencyOrContinue({dependency: '#album.trackCoverArtFileExtension'}),
 
-      // Fallback to 'jpg'.
       exposeConstant({
         value: 'jpg',
         update: {validate: isFileExtension},
@@ -175,13 +159,7 @@ export class Track extends Thing {
     // typically varies by release and isn't defined by the musical qualities
     // of the track.
     coverArtistContribs: compositeFrom(`Track.coverArtistContribs`, [
-      {
-        dependencies: ['disableUniqueCoverArt'],
-        compute: ({disableUniqueCoverArt}, continuation) =>
-          (disableUniqueCoverArt
-            ? null
-            : continuation()),
-      },
+      exitWithoutUniqueCoverArt(),
 
       withUpdateValueAsDependency(),
       withResolvedContribs({from: '#updateValue', into: '#coverArtistContribs'}),
@@ -559,6 +537,21 @@ function withHasUniqueCoverArt({
   ]);
 }
 
+// Shorthand for checking if the track has unique cover art and exposing a
+// fallback value if it isn't.
+function exitWithoutUniqueCoverArt({
+  value = null,
+} = {}) {
+  return compositeFrom(`exitWithoutUniqueCoverArt`, [
+    withHasUniqueCoverArt(),
+    exitWithoutDependency({
+      dependency: '#hasUniqueCoverArt',
+      mode: 'falsy',
+      value,
+    }),
+  ]);
+}
+
 function trackReverseReferenceList({
   property: refListProperty,
 }) {