« get me outta code hell

data: track: withDate - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-07 10:54:24 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:02 -0300
commitab0983e3c0aeddb78b0f6d7fa24e33ceaf034e90 (patch)
treeca4f4c8af7c3b175077c3f9a27ae9b25a61e0c0a /src/data
parentab98a1f8ea4c5d14e76d88e8ac2992b062e7e154 (diff)
data: track: withDate
Diffstat (limited to 'src/data')
-rw-r--r--src/data/composite/things/track/index.js1
-rw-r--r--src/data/composite/things/track/withDate.js34
-rw-r--r--src/data/things/track.js10
3 files changed, 38 insertions, 7 deletions
diff --git a/src/data/composite/things/track/index.js b/src/data/composite/things/track/index.js
index 14fbdef0..4f913a5e 100644
--- a/src/data/composite/things/track/index.js
+++ b/src/data/composite/things/track/index.js
@@ -7,6 +7,7 @@ export {default as trackReverseReferenceList} from './trackReverseReferenceList.
 export {default as withAlbum} from './withAlbum.js';
 export {default as withAlwaysReferenceByDirectory} from './withAlwaysReferenceByDirectory.js';
 export {default as withContainingTrackSection} from './withContainingTrackSection.js';
+export {default as withDate} from './withDate.js';
 export {default as withHasUniqueCoverArt} from './withHasUniqueCoverArt.js';
 export {default as withOriginalRelease} from './withOriginalRelease.js';
 export {default as withOtherReleases} from './withOtherReleases.js';
diff --git a/src/data/composite/things/track/withDate.js b/src/data/composite/things/track/withDate.js
new file mode 100644
index 00000000..b5a770e9
--- /dev/null
+++ b/src/data/composite/things/track/withDate.js
@@ -0,0 +1,34 @@
+// Gets the track's own date. This is either its dateFirstReleased property
+// or, if unset, the album's date.
+
+import {input, templateCompositeFrom} from '#composite';
+
+import withPropertyFromAlbum from './withPropertyFromAlbum.js';
+
+export default templateCompositeFrom({
+  annotation: `withDate`,
+
+  outputs: ['#date'],
+
+  steps: () => [
+    {
+      dependencies: ['dateFirstReleased'],
+      compute: (continuation, {dateFirstReleased}) =>
+        (dateFirstReleased
+          ? continuation.raiseOutput({'#date': dateFirstReleased})
+          : continuation()),
+    },
+
+    withPropertyFromAlbum({
+      property: input.value('date'),
+    }),
+
+    {
+      dependencies: ['#album.date'],
+      compute: (continuation, {['#album.date']: albumDate}) =>
+        (albumDate
+          ? continuation.raiseOutput({'#date': albumDate})
+          : continuation.raiseOutput({'#date': null})),
+    },
+  ],
+})
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 3ead059a..d9254196 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -62,6 +62,7 @@ import {
   withAlbum,
   withAlwaysReferenceByDirectory,
   withContainingTrackSection,
+  withDate,
   withHasUniqueCoverArt,
   withOriginalRelease,
   withOtherReleases,
@@ -336,13 +337,8 @@ export class Track extends Thing {
     ],
 
     date: [
-      exposeDependencyOrContinue({dependency: 'dateFirstReleased'}),
-
-      withPropertyFromAlbum({
-        property: input.value('date'),
-      }),
-
-      exposeDependency({dependency: '#album.date'}),
+      withDate(),
+      exposeDependency({dependency: '#date'}),
     ],
 
     hasUniqueCoverArt: [