« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/things/track/withSharedAdditionalNames.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/composite/things/track/withSharedAdditionalNames.js')
-rw-r--r--src/data/composite/things/track/withSharedAdditionalNames.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/data/composite/things/track/withSharedAdditionalNames.js b/src/data/composite/things/track/withSharedAdditionalNames.js
new file mode 100644
index 00000000..d205dc89
--- /dev/null
+++ b/src/data/composite/things/track/withSharedAdditionalNames.js
@@ -0,0 +1,46 @@
+// Compiles additional names directly provided on other releases.
+
+import {input, templateCompositeFrom} from '#composite';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {withFlattenedList} from '#composite/data';
+
+import CacheableObject from '#cacheable-object';
+
+import withOtherReleases from './withOtherReleases.js';
+
+export default templateCompositeFrom({
+  annotation: `withSharedAdditionalNames`,
+
+  outputs: ['#sharedAdditionalNames'],
+
+  steps: () => [
+    withOtherReleases(),
+
+    raiseOutputWithoutDependency({
+      dependency: '#otherReleases',
+      mode: input.value('empty'),
+      output: input.value({'#inferredAdditionalNames': []}),
+    }),
+
+    // TODO: Using getUpdateValue is always a bit janky.
+
+    {
+      dependencies: ['#otherReleases'],
+      compute: (continuation, {
+        ['#otherReleases']: otherReleases,
+      }) => continuation({
+        ['#otherReleases.additionalNames']:
+          otherReleases.map(release =>
+            CacheableObject.getUpdateValue(release, 'additionalNames')
+              ?? []),
+      }),
+    },
+
+    withFlattenedList({
+      list: '#otherReleases.additionalNames',
+    }).outputs({
+      '#flattenedList': '#sharedAdditionalNames',
+    }),
+  ],
+});