« 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/wiki-data/withCoverArtDate.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/composite/wiki-data/withCoverArtDate.js')
-rw-r--r--src/data/composite/wiki-data/withCoverArtDate.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/data/composite/wiki-data/withCoverArtDate.js b/src/data/composite/wiki-data/withCoverArtDate.js
new file mode 100644
index 00000000..0c644c77
--- /dev/null
+++ b/src/data/composite/wiki-data/withCoverArtDate.js
@@ -0,0 +1,70 @@
+// Gets the current thing's coverArtDate, or, if the 'fallback' option is set,
+// the thing's date. This is always null if the thing doesn't actually have
+// any coverArtistContribs.
+
+import {input, templateCompositeFrom} from '#composite';
+import {isDate} from '#validators';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+
+import withResolvedContribs from './withResolvedContribs.js';
+
+export default templateCompositeFrom({
+  annotation: `withCoverArtDate`,
+
+  inputs: {
+    from: input({
+      validate: isDate,
+      defaultDependency: 'coverArtDate',
+      acceptsNull: true,
+    }),
+
+    fallback: input({
+      type: 'boolean',
+      defaultValue: false,
+    }),
+  },
+
+  outputs: ['#coverArtDate'],
+
+  steps: () => [
+    withResolvedContribs({
+      from: 'coverArtistContribs',
+      date: input.value(null),
+    }),
+
+    raiseOutputWithoutDependency({
+      dependency: '#resolvedContribs',
+      mode: input.value('empty'),
+      output: input.value({'#coverArtDate': null}),
+    }),
+
+    {
+      dependencies: [input('from')],
+      compute: (continuation, {
+        [input('from')]: from,
+      }) =>
+        (from
+          ? continuation.raiseOutput({'#coverArtDate': from})
+          : continuation()),
+    },
+
+    {
+      dependencies: [input('fallback')],
+      compute: (continuation, {
+        [input('fallback')]: fallback,
+      }) =>
+        (fallback
+          ? continuation()
+          : continuation.raiseOutput({'#coverArtDate': null})),
+    },
+
+    {
+      dependencies: ['date'],
+      compute: (continuation, {date}) =>
+        (date
+          ? continuation.raiseOutput({'#coverArtDate': date})
+          : continuation.raiseOutput({'#coverArtDate': null})),
+    },
+  ],
+});