« get me outta code hell

data: fix compute() bugs in Thing.composite.from() - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-21 21:17:02 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-05 21:02:48 -0300
commit128c47001a639d1569bdfadf783ccede22116350 (patch)
treeb930f40890606d5570d0e8329f3263e2a3b7c6a6 /src
parent9e23a5a9eff30af0d7c8e356520dec791aebd38f (diff)
data: fix compute() bugs in Thing.composite.from()
Diffstat (limited to 'src')
-rw-r--r--src/data/things/thing.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 143c1515..111de550 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -420,6 +420,8 @@ export default class Thing extends CacheableObject {
   }
 
   static findArtistsFromContribs(contribsByRef, artistData) {
+    if (empty(contribsByRef)) return null;
+
     return (
       contribsByRef
         .map(({who, what}) => ({
@@ -518,7 +520,7 @@ export default class Thing extends CacheableObject {
               const result =
                 (type === 'transform'
                   ? fn(valueSoFar, dependencies, (updatedValue, providedDependencies) => {
-                      valueSoFar = updatedValue;
+                      valueSoFar = updatedValue ?? null;
                       Object.assign(dependencies, providedDependencies ?? {});
                       return continuationSymbol;
                     })
@@ -532,7 +534,11 @@ export default class Thing extends CacheableObject {
               }
             }
 
-            return base.expose.transform(valueSoFar, dependencies);
+            if (base.expose.transform) {
+              return base.expose.transform(valueSoFar, dependencies);
+            } else {
+              return base.expose.compute(dependencies);
+            }
           };
         } else {
           expose.compute = (initialDependencies) => {
@@ -540,7 +546,7 @@ export default class Thing extends CacheableObject {
 
             for (const {fn} of exposeFunctionOrder) {
               const result =
-                fn(valueSoFar, dependencies, providedDependencies => {
+                fn(dependencies, providedDependencies => {
                   Object.assign(dependencies, providedDependencies ?? {});
                   return continuationSymbol;
                 });