« get me outta code hell

data: withCoverArtDate refactor, make Album.coverArtDate updatable - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-07 12:27:34 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:04 -0300
commitea2e91a7ef5c38ecea57222601eae469e7d700f4 (patch)
treeef6255f242501ba4babf7f9fb6ae9abdfecf38bb
parentfbdf770209d984133ac081ba455f195220613fd2 (diff)
data: withCoverArtDate refactor, make Album.coverArtDate updatable
-rw-r--r--src/data/composite/wiki-data/withCoverArtDate.js24
-rw-r--r--src/data/things/album.js4
2 files changed, 23 insertions, 5 deletions
diff --git a/src/data/composite/wiki-data/withCoverArtDate.js b/src/data/composite/wiki-data/withCoverArtDate.js
index 7c16ce0f..0c644c77 100644
--- a/src/data/composite/wiki-data/withCoverArtDate.js
+++ b/src/data/composite/wiki-data/withCoverArtDate.js
@@ -3,6 +3,7 @@
 // any coverArtistContribs.
 
 import {input, templateCompositeFrom} from '#composite';
+import {isDate} from '#validators';
 
 import {raiseOutputWithoutDependency} from '#composite/control-flow';
 
@@ -12,6 +13,12 @@ export default templateCompositeFrom({
   annotation: `withCoverArtDate`,
 
   inputs: {
+    from: input({
+      validate: isDate,
+      defaultDependency: 'coverArtDate',
+      acceptsNull: true,
+    }),
+
     fallback: input({
       type: 'boolean',
       defaultValue: false,
@@ -33,14 +40,21 @@ export default templateCompositeFrom({
     }),
 
     {
-      dependencies: ['coverArtDate', input('fallback')],
+      dependencies: [input('from')],
+      compute: (continuation, {
+        [input('from')]: from,
+      }) =>
+        (from
+          ? continuation.raiseOutput({'#coverArtDate': from})
+          : continuation()),
+    },
+
+    {
+      dependencies: [input('fallback')],
       compute: (continuation, {
-        ['coverArtDate']: coverArtDate,
         [input('fallback')]: fallback,
       }) =>
-        (coverArtDate
-          ? continuation.raiseOutput({'#coverArtDate': coverArtDate})
-       : fallback
+        (fallback
           ? continuation()
           : continuation.raiseOutput({'#coverArtDate': null})),
     },
diff --git a/src/data/things/album.js b/src/data/things/album.js
index b0a46af1..ae5226ba 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -80,6 +80,10 @@ export class Album extends Thing {
     coverArtDate: [
       // TODO: Why does this fall back, but Track.coverArtDate doesn't?
       withCoverArtDate({
+        from: input.updateValue({
+          validate: isDate,
+        }),
+
         fallback: input.value(true),
       }),