From 450526565e92a5c914268bfcc653a95b44752393 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 16 Apr 2025 18:10:39 -0300 Subject: data: Artwork.{isMainArtwork,mainArtwork,siblingArtworks} --- src/data/composite/things/artwork/index.js | 1 + .../things/artwork/withContainingArtworkList.js | 46 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/data/composite/things/artwork/withContainingArtworkList.js (limited to 'src/data/composite/things') diff --git a/src/data/composite/things/artwork/index.js b/src/data/composite/things/artwork/index.js index b92bff72..e2661b50 100644 --- a/src/data/composite/things/artwork/index.js +++ b/src/data/composite/things/artwork/index.js @@ -1 +1,2 @@ +export {default as withContainingArtworkList} from './withContainingArtworkList.js'; export {default as withDate} from './withDate.js'; diff --git a/src/data/composite/things/artwork/withContainingArtworkList.js b/src/data/composite/things/artwork/withContainingArtworkList.js new file mode 100644 index 00000000..9c928ffd --- /dev/null +++ b/src/data/composite/things/artwork/withContainingArtworkList.js @@ -0,0 +1,46 @@ +// Gets the list of artworks which contains this one, which is functionally +// equivalent to `this.thing[this.thingProperty]`. If the exposed value is not +// a list at all (i.e. the property holds a single artwork), this composition +// outputs null. + +import {input, templateCompositeFrom} from '#composite'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; +import {withPropertyFromObject} from '#composite/data'; + +export default templateCompositeFrom({ + annotation: `withContainingArtworkList`, + + outputs: ['#containingArtworkList'], + + steps: () => [ + raiseOutputWithoutDependency({ + dependency: 'thing', + output: input.value({'#containingArtworkList': null}), + }), + + raiseOutputWithoutDependency({ + dependency: 'thingProperty', + output: input.value({'#containingArtworkList': null}), + }), + + withPropertyFromObject({ + object: 'thing', + property: 'thingProperty', + }).outputs({ + '#value': '#containingValue', + }), + + { + dependencies: ['#containingValue'], + compute: (continuation, { + ['#containingValue']: containingValue, + }) => continuation({ + ['#containingArtworkList']: + (Array.isArray(containingValue) + ? containingValue + : null), + }), + }, + ], +}); -- cgit 1.3.0-6-gf8a5