« get me outta code hell

data: fix update collation from steps - 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-09-21 15:30:49 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-21 15:30:49 -0300
commitc1018a0163ae28dc122aad7cb292a5e805c3d25a (patch)
treed2cabea77e11e02f766efacc258735e395682890 /src
parente3e8a904c24e71f303a1f29c8f1700478d929901 (diff)
data: fix update collation from steps
Diffstat (limited to 'src')
-rw-r--r--src/data/things/composite.js48
-rw-r--r--src/data/things/thing.js35
2 files changed, 37 insertions, 46 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index 38b7bcc9..f744f604 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -573,13 +573,22 @@ export function templateCompositeFrom(description) {
 
     inputOptionsAggregate.close();
 
+    const inputMetadata = getStaticInputMetadata(inputOptions);
+
     const expectedOutputNames =
       (Array.isArray(description.outputs)
         ? description.outputs
      : typeof description.outputs === 'function'
-        ? description.outputs(getStaticInputMetadata(inputOptions))
+        ? description.outputs(inputMetadata)
         : []);
 
+    const ownUpdateDescription =
+      (typeof description.update === 'object'
+        ? description.update
+     : typeof description.update === 'function'
+        ? description.update(inputMetadata)
+        : null);
+
     const outputOptions = {};
 
     const instantiatedTemplate = {
@@ -644,8 +653,8 @@ export function templateCompositeFrom(description) {
           finalDescription.compose = description.compose;
         }
 
-        if ('update' in description) {
-          finalDescription.update = description.update;
+        if (ownUpdateDescription) {
+          finalDescription.update = ownUpdateDescription;
         }
 
         if ('inputs' in description) {
@@ -820,7 +829,6 @@ export function compositeFrom(description) {
   const compositionNests = description.compose ?? true;
 
   const exposeDependencies = new Set();
-  const updateDescription = {};
 
   // Steps default to exposing if using a shorthand syntax where flags aren't
   // specified at all.
@@ -932,7 +940,6 @@ export function compositeFrom(description) {
   const stepEntries = stitchArrays({
     step: steps,
     expose: stepExposeDescriptions,
-    update: stepUpdateDescriptions,
     stepComposes: stepsCompose,
     stepComputes: stepsCompute,
     stepTransforms: stepsTransform,
@@ -942,7 +949,6 @@ export function compositeFrom(description) {
     const {
       step,
       expose,
-      update,
       stepComposes,
       stepComputes,
       stepTransforms,
@@ -974,12 +980,6 @@ export function compositeFrom(description) {
         return push(new TypeError(
           `Steps which only transform can't be used in a composition that doesn't update`));
       }
-
-      if (update) {
-        // TODO: This is a dumb assign statement, and it could probably do more
-        // interesting things, like combining validation functions.
-        Object.assign(updateDescription, update);
-      }
     });
   }
 
@@ -1332,8 +1332,13 @@ export function compositeFrom(description) {
     compose: compositionNests,
   };
 
-  if (constructedDescriptor.update) {
-    constructedDescriptor.update = updateDescription;
+  if (compositionUpdates) {
+    // TODO: This is a dumb assign statement, and it could probably do more
+    // interesting things, like combining validation functions.
+    constructedDescriptor.update =
+      Object.assign(
+        {...description.update ?? {}},
+        ...stepUpdateDescriptions.filter(Boolean));
   }
 
   if (compositionExposes) {
@@ -1569,15 +1574,12 @@ export const exposeUpdateValueOrContinue = templateCompositeFrom({
     validate: input({type: 'function', null: true}),
   },
 
-  update: {
-    dependencies: [input.staticValue('validate')],
-    compute: ({
-      [input.staticValue('validate')]: validate,
-    }) =>
-      (validate
-        ? {validate}
-        : {}),
-  },
+  update: ({
+    [input.staticValue('validate')]: validate,
+  }) =>
+    (validate
+      ? {validate}
+      : {}),
 
   steps: () => [
     exposeDependencyOrContinue({
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 0dea1fa4..ca1018eb 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -281,24 +281,19 @@ export const referenceList = templateCompositeFrom({
   compose: false,
 
   inputs: {
-    class: input(thingClassInput),
+    class: input.staticValue(thingClassInput),
+
     find: input({type: 'function'}),
 
     // todo: validate
     data: input(),
   },
 
-  update: {
-    dependencies: [
-      input.staticValue('class'),
-    ],
-
-    compute({
-      [input.staticValue('class')]: thingClass,
-    }) {
-      const {[Thing.referenceType]: referenceType} = thingClass;
-      return {validate: validateReferenceList(referenceType)};
-    },
+  update: ({
+    [input.staticValue('class')]: thingClass,
+  }) => {
+    const {[Thing.referenceType]: referenceType} = thingClass;
+    return {validate: validateReferenceList(referenceType)};
   },
 
   steps: () => [
@@ -326,17 +321,11 @@ export const singleReference = templateCompositeFrom({
     data: input(),
   },
 
-  update: {
-    dependencies: [
-      input.staticValue('class'),
-    ],
-
-    compute({
-      [input.staticValue('class')]: thingClass,
-    }) {
-      const {[Thing.referenceType]: referenceType} = thingClass;
-      return {validate: validateReference(referenceType)};
-    },
+  update: ({
+    [input.staticValue('class')]: thingClass,
+  }) => {
+    const {[Thing.referenceType]: referenceType} = thingClass;
+    return {validate: validateReference(referenceType)};
   },
 
   steps: () => [