From 61a666d547b25581f52bc8f5976419e8ce3658bd Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 4 Mar 2024 20:34:01 -0400 Subject: data: contribution: countIn{Contribution,Duration}Totals --- src/data/composite/things/contribution/index.js | 1 + .../contribution/inheritFromContributionPresets.js | 76 ++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/data/composite/things/contribution/inheritFromContributionPresets.js (limited to 'src/data/composite/things/contribution') diff --git a/src/data/composite/things/contribution/index.js b/src/data/composite/things/contribution/index.js index e912dadc..2cc69254 100644 --- a/src/data/composite/things/contribution/index.js +++ b/src/data/composite/things/contribution/index.js @@ -1,3 +1,4 @@ +export {default as inheritFromContributionPresets} from './inheritFromContributionPresets.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/inheritFromContributionPresets.js b/src/data/composite/things/contribution/inheritFromContributionPresets.js new file mode 100644 index 00000000..72642957 --- /dev/null +++ b/src/data/composite/things/contribution/inheritFromContributionPresets.js @@ -0,0 +1,76 @@ +import {input, templateCompositeFrom} from '#composite'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; +import {withPropertyFromList, withPropertyFromObject} from '#composite/data'; + +import withMatchingContributionPresets + from './withMatchingContributionPresets.js'; + +export default templateCompositeFrom({ + annotation: `inheritFromContributionPresets`, + + inputs: { + property: input({type: 'string'}), + }, + + steps: () => [ + withMatchingContributionPresets().outputs({ + '#matchingContributionPresets': '#presets', + }), + + raiseOutputWithoutDependency({ + dependency: '#presets', + mode: input.value('empty'), + }), + + withPropertyFromList({ + list: '#presets', + property: input('property'), + }), + + { + dependencies: ['#values'], + + compute: (continuation, { + ['#values']: values, + }) => continuation({ + ['#presetIndex']: + values.findIndex(value => + value !== undefined && + value !== null), + }), + }, + + raiseOutputWithoutDependency({ + dependency: '#presetIndex', + mode: input.value('index'), + }), + + { + dependencies: ['#presets', '#presetIndex'], + + compute: (continuation, { + ['#presets']: presets, + ['#presetIndex']: presetIndex, + }) => continuation({ + ['#preset']: + presets[presetIndex], + }), + }, + + withPropertyFromObject({ + object: '#preset', + property: input('property'), + }), + + // Can't use exposeDependency here since it doesn't compose, and so looks + // unfit to serve as the composition's base - even though we'll have raised + // out of this composition in the relevant cases already! + { + dependencies: ['#value'], + compute: (continuation, { + ['#value']: value, + }) => continuation.exit(value), + }, + ], +}); -- cgit 1.3.0-6-gf8a5