From d8ac315809796da6988211fa2887c599a312bee3 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 4 Mar 2024 20:16:39 -0400 Subject: composite: 'thisProperty' self-reflection --- src/data/cacheable-object.js | 9 +++++++-- src/data/composite.js | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/data/cacheable-object.js b/src/data/cacheable-object.js index addc225b..5e26c5f2 100644 --- a/src/data/cacheable-object.js +++ b/src/data/cacheable-object.js @@ -255,7 +255,8 @@ export default class CacheableObject { if (expose.dependencies?.length > 0) { const dependencyKeys = expose.dependencies.slice(); - const shouldReflect = dependencyKeys.includes('this'); + const shouldReflectObject = dependencyKeys.includes('this'); + const shouldReflectProperty = dependencyKeys.includes('thisProperty'); getAllDependencies = () => { const dependencies = Object.create(null); @@ -264,10 +265,14 @@ export default class CacheableObject { dependencies[key] = this.#propertyUpdateValues[key]; } - if (shouldReflect) { + if (shouldReflectObject) { dependencies.this = this; } + if (shouldReflectProperty) { + dependencies.thisProperty = property; + } + return dependencies; }; } else { diff --git a/src/data/composite.js b/src/data/composite.js index 7a98c424..0ace26e5 100644 --- a/src/data/composite.js +++ b/src/data/composite.js @@ -29,6 +29,7 @@ input.value = _valueIntoToken('input.value'); input.dependency = _valueIntoToken('input.dependency'); input.myself = () => Symbol.for(`hsmusic.composite.input.myself`); +input.thisProperty = () => Symbol.for('hsmusic.composite.input.thisProperty'); input.updateValue = _valueIntoToken('input.updateValue'); @@ -284,6 +285,7 @@ export function templateCompositeFrom(description) { 'input.value', 'input.dependency', 'input.myself', + 'input.thisProperty', 'input.updateValue', ].includes(tokenShape)) { expectedValueProvidingTokenInputNames.push(name); @@ -567,6 +569,8 @@ export function compositeFrom(description) { return token; case 'input.myself': return 'this'; + case 'input.thisProperty': + return 'thisProperty'; default: return null; } @@ -721,6 +725,8 @@ export function compositeFrom(description) { return (tokenValue.startsWith('#') ? null : tokenValue); case 'input.myself': return 'this'; + case 'input.thisProperty': + return 'thisProperty'; default: return null; } @@ -877,6 +883,8 @@ export function compositeFrom(description) { return valueSoFar; case 'input.myself': return initialDependencies['this']; + case 'input.thisProperty': + return initialDependencies['thisProperty']; case 'input': return initialDependencies[token]; default: @@ -969,6 +977,7 @@ export function compositeFrom(description) { ? {[input.updateValue()]: valueSoFar} : {}), [input.myself()]: initialDependencies?.['this'] ?? null, + [input.thisProperty()]: initialDependencies?.['thisProperty'] ?? null, }; const selectDependencies = @@ -983,6 +992,8 @@ export function compositeFrom(description) { return dependency; case 'input.myself': return input.myself(); + case 'input.thisProperty': + return input.thisProperty(); case 'input.dependency': return tokenValue; case 'input.updateValue': -- cgit 1.3.0-6-gf8a5