« get me outta code hell

data: exitWithoutContribs utility - 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-09-09 09:33:04 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-09 09:33:04 -0300
commit9109356037ce98af378765302841c957cc96b8d8 (patch)
treebb72dc3976d962e2ce81f5d32028c627f60a2f37
parenta9b96deeca6b2dacb7fac309c47e7bc6289270e6 (diff)
data: exitWithoutContribs utility
-rw-r--r--src/data/things/album.js9
-rw-r--r--src/data/things/thing.js17
2 files changed, 20 insertions, 6 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 0785953..dc8d318 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -23,6 +23,7 @@ import Thing, {
   contributionList,
   dimensions,
   directory,
+  exitWithoutContribs,
   fileExtension,
   flag,
   name,
@@ -31,7 +32,6 @@ import Thing, {
   simpleString,
   urls,
   wikiData,
-  withResolvedContribs,
   withResolvedReferenceList,
 } from './thing.js';
 
@@ -51,9 +51,7 @@ export class Album extends Thing {
     dateAddedToWiki: simpleDate(),
 
     coverArtDate: [
-      withResolvedContribs({from: 'coverArtistContribs'}),
-      exitWithoutDependency({dependency: '#resolvedContribs', mode: 'empty'}),
-
+      exitWithoutContribs({contribs: 'coverArtistContribs'}),
       exposeUpdateValueOrContinue(),
       exposeDependency({
         dependency: 'date',
@@ -152,8 +150,7 @@ export class Album extends Thing {
     ],
 
     coverArtFileExtension: [
-      withResolvedContribs({from: 'coverArtistContribs'}),
-      exitWithoutDependency({dependency: '#resolvedContribs', mode: 'empty'}),
+      exitWithoutContribs({contribs: 'coverArtistContribs'}),
       fileExtension('jpg'),
     ],
 
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 52f0b77..fe9000b 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -436,6 +436,23 @@ export function withResolvedContribs({
   ]);
 }
 
+// Shorthand for exiting if the contribution list (usually a property's update
+// value) resolves to empty - ensuring that the later computed results are only
+// returned if these contributions are present.
+export function exitWithoutContribs({
+  contribs,
+  value = null,
+}) {
+  return compositeFrom(`exitWithoutContribs`, [
+    withResolvedContribs({from: contribs}),
+    exitWithoutDependency({
+      dependency: '#resolvedContribs',
+      mode: 'empty',
+      value,
+    }),
+  ]);
+}
+
 // Resolves a reference by using the provided find function to match it
 // within the provided thingData dependency. This will early exit if the
 // data dependency is null, or, if notFoundMode is set to 'exit', if the find