diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-04-22 18:03:53 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-04-22 18:03:53 -0300 |
commit | b39f8dcaba0b2f0778a2cbb20505b59cb3d3c57e (patch) | |
tree | c371953093d373b2cef93286bbdd319978e56461 /src/data/composite/things/artwork/withPropertyFromMainArtwork.js | |
parent | 35cb9954edae70266dd3b174897648032fa084bc (diff) |
data: Artwork.{artTags,artistContribs}: inherit from attached
Diffstat (limited to 'src/data/composite/things/artwork/withPropertyFromMainArtwork.js')
-rw-r--r-- | src/data/composite/things/artwork/withPropertyFromMainArtwork.js | 100 |
1 files changed, 100 insertions, 0 deletions
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}), + }, + ], +}); |