From 3b458e5c403054bda58733e238ab666596cc9f70 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 23 Sep 2023 22:12:54 -0300 Subject: data: refactor/tidy input token construction --- src/data/things/composite.js | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/data/things/composite.js b/src/data/things/composite.js index fdb80cf..293952b 100644 --- a/src/data/things/composite.js +++ b/src/data/things/composite.js @@ -355,35 +355,30 @@ import { const globalCompositeCache = {}; -export function input(nameOrDescription) { - if (typeof nameOrDescription === 'string') { - return Symbol.for(`hsmusic.composite.input:${nameOrDescription}`); - } else { - return { - symbol: Symbol.for('hsmusic.composite.input'), - shape: 'input', - value: nameOrDescription, - }; - } -} +const _valueIntoToken = shape => + (value = null) => + (value === null + ? Symbol.for(`hsmusic.composite.${shape}`) + : typeof value === 'string' + ? Symbol.for(`hsmusic.composite.${shape}:${value}`) + : { + symbol: Symbol.for(`hsmusic.composite.input`), + shape, + value, + }); +export const input = _valueIntoToken('input'); input.symbol = Symbol.for('hsmusic.composite.input'); -input.updateValue = (description = null) => - (description - ? { - symbol: input.symbol, - shape: 'input.updateValue', - value: description, - } - : Symbol.for('hsmusic.composite.input.updateValue')); +input.value = _valueIntoToken('input.value'); +input.dependency = _valueIntoToken('input.dependency'); input.myself = () => Symbol.for(`hsmusic.composite.input.myself`); -input.value = value => ({symbol: input.symbol, shape: 'input.value', value}); -input.dependency = name => Symbol.for(`hsmusic.composite.input.dependency:${name}`); -input.staticDependency = name => Symbol.for(`hsmusic.composite.input.staticDependency:${name}`); -input.staticValue = name => Symbol.for(`hsmusic.composite.input.staticValue:${name}`); +input.updateValue = _valueIntoToken('input.updateValue'); + +input.staticDependency = _valueIntoToken('input.staticDependency'); +input.staticValue = _valueIntoToken('input.staticValue'); function isInputToken(token) { if (typeof token === 'object') { -- cgit 1.3.0-6-gf8a5