From cb124756780e41c6791981233da4b56c031d6142 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 21 Sep 2023 15:52:46 -0300 Subject: data: support update description in input.updateValue() --- src/data/things/composite.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/data') diff --git a/src/data/things/composite.js b/src/data/things/composite.js index f744f604..e6cc267a 100644 --- a/src/data/things/composite.js +++ b/src/data/things/composite.js @@ -369,7 +369,15 @@ export function input(nameOrDescription) { input.symbol = Symbol.for('hsmusic.composite.input'); -input.updateValue = () => Symbol.for('hsmusic.composite.input.updateValue'); +input.updateValue = (description = null) => + (description + ? { + symbol: input.symbol, + shape: 'input.updateValue', + value: description, + } + : Symbol.for('hsmusic.composite.input.updateValue')); + input.myself = () => Symbol.for(`hsmusic.composite.input.myself`); input.value = value => ({symbol: input.symbol, shape: 'input.value', value}); @@ -814,7 +822,9 @@ export function compositeFrom(description) { .filter(Boolean); const anyInputsUseUpdateValue = - dependenciesFromInputs.includes(input.updateValue()); + dependenciesFromInputs + .filter(dependency => isInputToken(dependency)) + .some(token => getInputTokenShape(token) === 'input.updateValue'); const base = composition.at(-1); const steps = composition.slice(); @@ -871,13 +881,22 @@ export function compositeFrom(description) { : null)); // The update description for a step, if present at all, is always set - // explicitly. + // explicitly. There may be multiple per step - namely that step's own + // {update} description, and any descriptions passed as the value in an + // input.updateValue({...}) token. const stepUpdateDescriptions = steps .map((step, index) => (stepsUpdate[index] - ? step.update ?? null - : null)); + ? [ + step.update ?? null, + ...(stepExposeDescriptions[index]?.dependencies ?? []) + .filter(dependency => isInputToken(dependency)) + .filter(token => getInputTokenShape(token) === 'input.updateValue') + .map(token => getInputTokenValue(token)) + .filter(Boolean), + ] + : [])); // Indicates presence of a {compute} function on the expose description. const stepsCompute = @@ -1338,7 +1357,7 @@ export function compositeFrom(description) { constructedDescriptor.update = Object.assign( {...description.update ?? {}}, - ...stepUpdateDescriptions.filter(Boolean)); + ...stepUpdateDescriptions.flat()); } if (compositionExposes) { -- cgit 1.3.0-6-gf8a5