« get me outta code hell

data: contribution: countIn{Contribution,Duration}Totals - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/things/contribution/inheritFromContributionPresets.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-04 20:34:01 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:01 -0300
commit94bdc5e8356834e2cc22695e196ba4f50014d05f (patch)
tree29968ab17f5f00ccd8718b0aff5f80116bd1703b /src/data/composite/things/contribution/inheritFromContributionPresets.js
parent6d0ad85bc718c2429d8dc124bba1329cc9615d12 (diff)
data: contribution: countIn{Contribution,Duration}Totals
Diffstat (limited to 'src/data/composite/things/contribution/inheritFromContributionPresets.js')
-rw-r--r--src/data/composite/things/contribution/inheritFromContributionPresets.js76
1 files changed, 76 insertions, 0 deletions
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),
+    },
+  ],
+});