From b39f8dcaba0b2f0778a2cbb20505b59cb3d3c57e Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 22 Apr 2025 18:03:53 -0300 Subject: data: Artwork.{artTags,artistContribs}: inherit from attached --- .../things/artwork/withPropertyFromMainArtwork.js | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/data/composite/things/artwork/withPropertyFromMainArtwork.js (limited to 'src/data/composite/things/artwork/withPropertyFromMainArtwork.js') diff --git a/src/data/composite/things/artwork/withPropertyFromMainArtwork.js b/src/data/composite/things/artwork/withPropertyFromMainArtwork.js new file mode 100644 index 00000000..a0233119 --- /dev/null +++ b/src/data/composite/things/artwork/withPropertyFromMainArtwork.js @@ -0,0 +1,100 @@ +import {input, templateCompositeFrom} from '#composite'; + +import {withResultOfAvailabilityCheck} from '#composite/control-flow'; +import {withPropertyFromObject} from '#composite/data'; + +import withContainingArtworkList from './withContainingArtworkList.js'; + +function getOutputName({ + [input.staticValue('property')]: property, +}) { + if (property) { + return `#mainArtwork.${property}`; + } else { + return '#value'; + } +} + +export default templateCompositeFrom({ + annotation: `withPropertyFromMainArtwork`, + + inputs: { + property: input({type: 'string'}), + onlyIfAttached: input({type: 'boolean', defaultValue: false}), + }, + + outputs: inputs => [getOutputName(inputs)], + + steps: () => [ + { + dependencies: [input.staticValue('property')], + compute: (continuation, inputs) => + continuation({'#output': getOutputName(inputs)}), + }, + + { + dependencies: [input('onlyIfAttached'), 'attachAbove', '#output'], + compute: (continuation, { + [input('onlyIfAttached')]: onlyIfAttached, + ['attachAbove']: attachAbove, + ['#output']: output, + }) => + (onlyIfAttached && attachAbove + ? continuation() + : onlyIfAttached + ? continuation.raiseOutput({[output]: null}) + : continuation()), + }, + + withContainingArtworkList(), + + withResultOfAvailabilityCheck({ + from: '#containingArtworkList', + }), + + { + dependencies: ['#availability', '#output'], + compute: (continuation, { + ['#availability']: availability, + ['#output']: output, + }) => + (availability + ? continuation() + : continuation.raiseOutput({[output]: null})), + }, + + { + dependencies: ['#containingArtworkList'], + compute: (continuation, { + ['#containingArtworkList']: list, + }) => + continuation({'#mainArtwork': list[0]}), + }, + + { + dependencies: [input.myself(), '#mainArtwork', '#output'], + compute: (continuation, { + [input.myself()]: myself, + ['#mainArtwork']: mainArtwork, + ['#output']: output, + }) => + (myself === mainArtwork + ? continuation.raiseOutput({[output]: null}) + : continuation()), + }, + + withPropertyFromObject({ + object: '#mainArtwork', + property: input('property'), + }), + + { + dependencies: ['#value', '#output'], + compute: (continuation, { + ['#value']: value, + ['#output']: output, + }) => + continuation.raiseOutput({[output]: value}), + }, + ], +}); -- cgit 1.3.0-6-gf8a5