« get me outta code hell

data: Artist.totalDuration - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/things
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-06 14:28:35 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-12 17:26:37 -0300
commit878e09f8131fcf17f7a21ba1b5dbfdf6d9ad41e8 (patch)
tree8463864295d09cd2aec94de5cb77cfdbc9efd0f5 /src/data/composite/things
parent4dd54f8b38a38a47566a0006b1dba3065158fc7e (diff)
data: Artist.totalDuration
This is sort of a stub / proof of concept function.
The contained logic may be refactored a bit more still!
Diffstat (limited to 'src/data/composite/things')
-rw-r--r--src/data/composite/things/artist/artistTotalDuration.js72
-rw-r--r--src/data/composite/things/artist/index.js1
2 files changed, 73 insertions, 0 deletions
diff --git a/src/data/composite/things/artist/artistTotalDuration.js b/src/data/composite/things/artist/artistTotalDuration.js
new file mode 100644
index 00000000..54204918
--- /dev/null
+++ b/src/data/composite/things/artist/artistTotalDuration.js
@@ -0,0 +1,72 @@
+import {input, templateCompositeFrom} from '#composite';
+
+import {exposeDependency} from '#composite/control-flow';
+import {withFilteredList, withPropertyFromList} from '#composite/data';
+import {withContributionListSums, withReverseContributionList}
+  from '#composite/wiki-data';
+
+export default templateCompositeFrom({
+  annotation: `artistTotalDuration`,
+
+  compose: false,
+
+  steps: () => [
+    withReverseContributionList({
+      data: 'trackData',
+      list: input.value('artistContribs'),
+      mode: input.value('contributions'),
+    }).outputs({
+      '#reverseContributionList': '#contributionsAsArtist',
+    }),
+
+    withReverseContributionList({
+      data: 'trackData',
+      list: input.value('contributorContribs'),
+      mode: input.value('contributions'),
+    }).outputs({
+      '#reverseContributionList': '#contributionsAsContributor',
+    }),
+
+    {
+      dependencies: [
+        '#contributionsAsArtist',
+        '#contributionsAsContributor',
+      ],
+
+      compute: (continuation, {
+        ['#contributionsAsArtist']: artistContribs,
+        ['#contributionsAsContributor']: contributorContribs,
+      }) => continuation({
+        ['#allContributions']: [
+          ...artistContribs,
+          ...contributorContribs,
+        ],
+      }),
+    },
+
+    withPropertyFromList({
+      list: '#allContributions',
+      property: input.value('thing'),
+    }),
+
+    withPropertyFromList({
+      list: '#allContributions.thing',
+      property: input.value('isOriginalRelease'),
+    }),
+
+    withFilteredList({
+      list: '#allContributions',
+      filter: '#allContributions.thing.isOriginalRelease',
+    }).outputs({
+      '#filteredList': '#originalContributions',
+    }),
+
+    withContributionListSums({
+      list: '#originalContributions',
+    }),
+
+    exposeDependency({
+      dependency: '#contributionListDuration',
+    }),
+  ],
+});
diff --git a/src/data/composite/things/artist/index.js b/src/data/composite/things/artist/index.js
new file mode 100644
index 00000000..55514c71
--- /dev/null
+++ b/src/data/composite/things/artist/index.js
@@ -0,0 +1 @@
+export {default as artistTotalDuration} from './artistTotalDuration.js';