diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-09-21 15:52:46 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-09-21 15:52:46 -0300 |
commit | cb124756780e41c6791981233da4b56c031d6142 (patch) | |
tree | 0be2766198a9cafc15d43a37ba3b58c1dfe77fea /src/data/things | |
parent | c1018a0163ae28dc122aad7cb292a5e805c3d25a (diff) |
data: support update description in input.updateValue()
Diffstat (limited to 'src/data/things')
-rw-r--r-- | src/data/things/composite.js | 31 |
1 files changed, 25 insertions, 6 deletions
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) { |