From 36d72d8f910dc0b9200224236d67eec605290b56 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 10 Apr 2024 20:24:34 -0300 Subject: data, content: various property & thing-type matches --- src/data/composite/things/contribution/index.js | 2 ++ .../things/contribution/thingPropertyMatches.js | 33 ++++++++++++++++++ .../contribution/thingReferenceTypeMatches.js | 39 ++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 src/data/composite/things/contribution/thingPropertyMatches.js create mode 100644 src/data/composite/things/contribution/thingReferenceTypeMatches.js (limited to 'src/data/composite') diff --git a/src/data/composite/things/contribution/index.js b/src/data/composite/things/contribution/index.js index 2cc69254..2c812644 100644 --- a/src/data/composite/things/contribution/index.js +++ b/src/data/composite/things/contribution/index.js @@ -1,4 +1,6 @@ export {default as inheritFromContributionPresets} from './inheritFromContributionPresets.js'; +export {default as thingPropertyMatches} from './thingPropertyMatches.js'; +export {default as thingReferenceTypeMatches} from './thingReferenceTypeMatches.js'; export {default as withContributionArtist} from './withContributionArtist.js'; export {default as withContributionContext} from './withContributionContext.js'; export {default as withMatchingContributionPresets} from './withMatchingContributionPresets.js'; diff --git a/src/data/composite/things/contribution/thingPropertyMatches.js b/src/data/composite/things/contribution/thingPropertyMatches.js new file mode 100644 index 00000000..4a37f2cf --- /dev/null +++ b/src/data/composite/things/contribution/thingPropertyMatches.js @@ -0,0 +1,33 @@ +import {input, templateCompositeFrom} from '#composite'; + +import {exitWithoutDependency} from '#composite/control-flow'; + +export default templateCompositeFrom({ + annotation: `thingPropertyMatches`, + + compose: false, + + inputs: { + value: input({type: 'string'}), + }, + + steps: () => [ + exitWithoutDependency({ + dependency: 'thingProperty', + value: input.value(false), + }), + + { + dependencies: [ + 'thingProperty', + input('value'), + ], + + compute: ({ + ['thingProperty']: thingProperty, + [input('value')]: value, + }) => + thingProperty === value, + }, + ], +}); diff --git a/src/data/composite/things/contribution/thingReferenceTypeMatches.js b/src/data/composite/things/contribution/thingReferenceTypeMatches.js new file mode 100644 index 00000000..2ee811af --- /dev/null +++ b/src/data/composite/things/contribution/thingReferenceTypeMatches.js @@ -0,0 +1,39 @@ +import {input, templateCompositeFrom} from '#composite'; + +import {exitWithoutDependency} from '#composite/control-flow'; +import {withPropertyFromObject} from '#composite/data'; + +export default templateCompositeFrom({ + annotation: `thingReferenceTypeMatches`, + + compose: false, + + inputs: { + value: input({type: 'string'}), + }, + + steps: () => [ + exitWithoutDependency({ + dependency: 'thing', + value: input.value(false), + }), + + withPropertyFromObject({ + object: 'thing', + property: input.value('constructor'), + }), + + { + dependencies: [ + '#thing.constructor', + input('value'), + ], + + compute: ({ + ['#thing.constructor']: constructor, + [input('value')]: value, + }) => + constructor[Symbol.for('Thing.referenceType')] === value, + }, + ], +}); -- cgit 1.3.0-6-gf8a5