« get me outta code hell

data: track: null coverArtistContribs if hasTrackArt false - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-04-27 16:03:04 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-04-27 16:04:37 -0300
commit7e0dfb0f797b6dabad4a4491ef8e7333cc199926 (patch)
treed257a9e045355bf3645c5bf70fedcb2e95c0ac6b
parent878a96cb223783ef1b100fdb3bb9d795404c44f5 (diff)
data: track: null coverArtistContribs if hasTrackArt false
Fixes #178.

This commit also cleans up the documentation for the utility
used here, dynamicInheritContribs. These are the only two uses
of that utility at all but like, code comments very rarely hurt
and d'accord are probably even more useful here lol
-rw-r--r--src/data/things/thing.js26
-rw-r--r--src/data/things/track.js2
2 files changed, 23 insertions, 5 deletions
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 5ab15c0..9c59436 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -262,26 +262,42 @@ export default class Thing extends CacheableObject {
     // Dynamically inherit a contribution list from some other object, if it
     // hasn't been overridden on this object. This is handy for solo albums
     // where all tracks have the same artist, for example.
-    //
-    // Note: The arguments of this function aren't currently final! The final
-    // format will look more like (contribsByRef, parentContribsByRef), e.g.
-    // ('artistContribsByRef', '@album/artistContribsByRef').
     dynamicInheritContribs: (
+      // If this property is explicitly false, the contribution list returned
+      // will always be empty.
+      nullerProperty,
+
+      // Property holding contributions on the current object.
       contribsByRefProperty,
+
+      // Property holding corresponding "default" contributions on the parent
+      // object, which will fallen back to if the object doesn't have its own
+      // contribs.
       parentContribsByRefProperty,
+
+      // Data array to search in and "find" function to locate parent object
+      // (which will be passed the child object and the wiki data array).
       thingDataProperty,
       findFn
     ) => ({
       flags: {expose: true},
       expose: {
-        dependencies: [contribsByRefProperty, thingDataProperty, 'artistData'],
+        dependencies: [
+          contribsByRefProperty,
+          thingDataProperty,
+          nullerProperty,
+          'artistData',
+        ].filter(Boolean),
+
         compute({
           [Thing.instance]: thing,
+          [nullerProperty]: nuller,
           [contribsByRefProperty]: contribsByRef,
           [thingDataProperty]: thingData,
           artistData,
         }) {
           if (!artistData) return [];
+          if (nuller === false) return [];
           const refs =
             contribsByRef ??
             findFn(thing, thingData, {mode: 'quiet'})?.[parentContribsByRefProperty];
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 1c2013a..00585c1 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -245,6 +245,7 @@ export class Track extends Thing {
     },
 
     artistContribs: Thing.common.dynamicInheritContribs(
+      null,
       'artistContribsByRef',
       'artistContribsByRef',
       'albumData',
@@ -254,6 +255,7 @@ export class Track extends Thing {
     contributorContribs: Thing.common.dynamicContribs('contributorContribsByRef'),
 
     coverArtistContribs: Thing.common.dynamicInheritContribs(
+      'hasCoverArt',
       'coverArtistContribsByRef',
       'trackCoverArtistContribsByRef',
       'albumData',