« 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/withAlbum.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/composite/things/track/withAlbum.js')
-rw-r--r--src/data/composite/things/track/withAlbum.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/data/composite/things/track/withAlbum.js b/src/data/composite/things/track/withAlbum.js
new file mode 100644
index 0000000..03b840d
--- /dev/null
+++ b/src/data/composite/things/track/withAlbum.js
@@ -0,0 +1,22 @@
+// Gets the track's album. This will early exit if albumData is missing.
+// If there's no album whose list of tracks includes this track, the output
+// dependency will be null.
+
+import {input, templateCompositeFrom} from '#composite';
+
+import {withUniqueReferencingThing} from '#composite/wiki-data';
+
+export default templateCompositeFrom({
+  annotation: `withAlbum`,
+
+  outputs: ['#album'],
+
+  steps: () => [
+    withUniqueReferencingThing({
+      data: 'albumData',
+      list: input.value('tracks'),
+    }).outputs({
+      ['#uniqueReferencingThing']: '#album',
+    }),
+  ],
+});