« get me outta code hell

data, test: collate update description from composition inputs - 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-23 20:35:57 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-23 20:35:57 -0300
commitf3d98f5ea63db7f7b2155e7efb0812f025c5bcf3 (patch)
tree0c98d998b42da9f1f6f57a5fc49c93635bd8a1bc
parent8bcae16b391762f6b533654ec06c3bf0c8770d35 (diff)
data, test: collate update description from composition inputs
-rw-r--r--src/data/things/composite.js11
-rw-r--r--test/unit/data/composite/compositeFrom.js52
2 files changed, 61 insertions, 2 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index c0f0ab0b..34e550a1 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -837,6 +837,16 @@ export function compositeFrom(description) {
       .filter(dependency => isInputToken(dependency))
       .some(token => getInputTokenShape(token) === 'input.updateValue');
 
+  // Update descriptions passed as the value in an input.updateValue() token,
+  // as provided as inputs for this composition.
+  const inputUpdateDescriptions =
+    Object.values(description.inputs ?? {})
+      .map(token =>
+        (getInputTokenShape(token) === 'input.updateValue'
+          ? getInputTokenValue(token)
+          : null))
+      .filter(Boolean);
+
   const base = composition.at(-1);
   const steps = composition.slice();
 
@@ -1396,6 +1406,7 @@ export function compositeFrom(description) {
     constructedDescriptor.update =
       Object.assign(
         {...description.update ?? {}},
+        ...inputUpdateDescriptions,
         ...stepUpdateDescriptions.flat());
   }
 
diff --git a/test/unit/data/composite/compositeFrom.js b/test/unit/data/composite/compositeFrom.js
index faeef59a..6ae1e7bc 100644
--- a/test/unit/data/composite/compositeFrom.js
+++ b/test/unit/data/composite/compositeFrom.js
@@ -172,7 +172,7 @@ t.test(`compositeFrom: dependencies from inputs`, t => {
 });
 
 t.test(`compositeFrom: update from various sources`, t => {
-  t.plan(2);
+  t.plan(3);
 
   const match = {
     flags: {update: true, expose: true, compose: false},
@@ -232,6 +232,54 @@ t.test(`compositeFrom: update from various sources`, t => {
     });
 
     t.match(composite, match);
-    t.equal(debugComposite(() => composite.expose.transform('foo')), 'Xx_foofoo_xX');
+    t.equal(composite.expose.transform('foo'), 'Xx_foofoo_xX');
+  });
+
+  t.test(`compositeFrom: update from inputs`, t => {
+    t.plan(3);
+
+    const composite = compositeFrom({
+      inputs: {
+        myInput: input.updateValue({
+          validate: isString,
+          default: 'foo',
+        }),
+      },
+
+      steps: [
+        {
+          dependencies: [input('myInput')],
+          compute: (continuation, {
+            [input('myInput')]: value,
+          }) => continuation({
+            '#value': `Xx_${value.repeat(2)}_xX`,
+          }),
+        },
+
+        {
+          dependencies: ['#value'],
+          transform: (_value, continuation, {'#value': value}) =>
+            continuation(value),
+        },
+      ],
+    });
+
+    let continuationValue = null;
+    const continuation = value => {
+      continuationValue = value;
+      return continuationSymbol;
+    };
+
+    t.match(composite, {
+      ...match,
+
+      flags: {update: true, expose: true, compose: true},
+    });
+
+    t.equal(
+      composite.expose.transform('foo', continuation),
+      continuationSymbol);
+
+    t.equal(continuationValue, 'Xx_foofoo_xX');
   });
 });