« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things/composite.js26
-rw-r--r--src/data/things/thing.js30
2 files changed, 30 insertions, 26 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index 1be60cd1..bf2d11ea 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -331,6 +331,7 @@
 // syntax as for other compositional steps, and it'll work out cleanly!
 //
 
+import find from '#find';
 import {empty, filterProperties, openAggregate} from '#sugar';
 
 import Thing from './thing.js';
@@ -1102,20 +1103,33 @@ export function raiseWithoutUpdateValue({
 // means mapping the "who" reference of each contribution to an artist
 // object, and filtering out those whose "who" doesn't match any artist.
 export function withResolvedContribs({from, to}) {
-  return {
-    annotation: `Thing.composite.withResolvedContribs`,
-    flags: {expose: true, compose: true},
+  return Thing.composite.from(`Thing.composite.withResolvedContribs`, [
+    Thing.composite.earlyExitWithoutDependency('artistData', {
+      value: [],
+    }),
 
-    expose: {
+    Thing.composite.raiseWithoutDependency(from, {
+      mode: 'empty',
+      map: {to},
+      raise: {to: []},
+    }),
+
+    {
       dependencies: ['artistData'],
       mapDependencies: {from},
       mapContinuation: {to},
       compute: ({artistData, from}, continuation) =>
         continuation({
-          to: Thing.findArtistsFromContribs(from, artistData),
+          to:
+            from
+              .map(({who, what}) => ({
+                who: find.artist(who, artistData, {mode: 'quiet'}),
+                what,
+              }))
+              .filter(({who}) => who),
         }),
     },
-  };
+  ]);
 }
 
 // Resolves a reference by using the provided find function to match it
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 01aa8b1b..9bfed080 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -249,14 +249,16 @@ export default class Thing extends CacheableObject {
     // filtered out. (So if the list is all empty, chances are that either the
     // reference list is somehow messed up, or artistData isn't being provided
     // properly.)
-    dynamicContribs: (contribsByRefProperty) => ({
-      flags: {expose: true},
-      expose: {
-        dependencies: ['artistData', contribsByRefProperty],
-        compute: ({artistData, [contribsByRefProperty]: contribsByRef}) =>
-          Thing.findArtistsFromContribs(contribsByRef, artistData),
-      },
-    }),
+    dynamicContribs(contribsByRefProperty) {
+      return Thing.composite.from(`Thing.common.dynamicContribs`, [
+        Thing.composite.withResolvedContribs({
+          from: contribsByRefProperty,
+          to: '#contribs',
+        }),
+
+        Thing.composite.exposeDependency('#contribs'),
+      ]);
+    },
 
     // Nice 'n simple shorthand for an exposed-only flag which is true when any
     // contributions are present in the specified property.
@@ -348,17 +350,5 @@ export default class Thing extends CacheableObject {
     return `${thing.constructor[Thing.referenceType]}:${thing.directory}`;
   }
 
-  static findArtistsFromContribs(contribsByRef, artistData) {
-    if (empty(contribsByRef)) return null;
-
-    return (
-      contribsByRef
-        .map(({who, what}) => ({
-          who: find.artist(who, artistData, {mode: 'quiet'}),
-          what,
-        }))
-        .filter(({who}) => who));
-  }
-
   static composite = composite;
 }