« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/wiki-data/index.js1
-rw-r--r--src/data/composite/wiki-data/withRecontextualizedContributionList.js77
-rw-r--r--src/data/things/track.js11
3 files changed, 88 insertions, 1 deletions
diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js
index 15ebaffa..a0a6be7f 100644
--- a/src/data/composite/wiki-data/index.js
+++ b/src/data/composite/wiki-data/index.js
@@ -9,6 +9,7 @@ export {default as inputWikiData} from './inputWikiData.js';
 export {default as withDirectory} from './withDirectory.js';
 export {default as withDirectoryFromName} from './withDirectoryFromName.js';
 export {default as withParsedCommentaryEntries} from './withParsedCommentaryEntries.js';
+export {default as withRecontextualizedContributionList} from './withRecontextualizedContributionList.js';
 export {default as withResolvedContribs} from './withResolvedContribs.js';
 export {default as withResolvedReference} from './withResolvedReference.js';
 export {default as withResolvedReferenceList} from './withResolvedReferenceList.js';
diff --git a/src/data/composite/wiki-data/withRecontextualizedContributionList.js b/src/data/composite/wiki-data/withRecontextualizedContributionList.js
new file mode 100644
index 00000000..418b346f
--- /dev/null
+++ b/src/data/composite/wiki-data/withRecontextualizedContributionList.js
@@ -0,0 +1,77 @@
+// Clones all the contributions in a list, with thing and thingProperty both
+// updated to match the current thing. Overwrite the provided dependency.
+// Doesn't do anything if the provided dependency is null.
+
+import CacheableObject from '#cacheable-object';
+import {input, templateCompositeFrom} from '#composite';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {withMappedList} from '#composite/data';
+
+export default templateCompositeFrom({
+  annotation: `withRecontextualizedContributionList`,
+
+  inputs: {
+    list: input.staticDependency({
+      type: 'array',
+      acceptsNull: true,
+    }),
+  },
+
+  outputs: ({
+    [input.staticDependency('list')]: list,
+  }) => [list],
+
+  steps: () => [
+    raiseOutputWithoutDependency({
+      dependency: input('list'),
+    }),
+
+    {
+      dependencies: [input.myself(), input.thisProperty()],
+
+      compute: (continuation, {
+        [input.myself()]: myself,
+        [input.thisProperty()]: thisProperty,
+      }) => continuation({
+        ['#assignment']: {
+          thing: myself,
+          thingProperty: thisProperty,
+        },
+      }),
+    },
+
+    {
+      dependencies: ['#assignment'],
+
+      compute: (continuation, {
+        ['#assignment']: assignment,
+      }) => continuation({
+        ['#map']:
+          contrib =>
+            Object.assign(
+              CacheableObject.clone(contrib),
+              assignment),
+      }),
+    },
+
+    withMappedList({
+      list: input('list'),
+      map: '#map',
+    }).outputs({
+      '#mappedList': '#newContributions',
+    }),
+
+    {
+      dependencies: [input.staticDependency('list'), '#newContributions'],
+
+      compute: (continuation, {
+        [input.staticDependency('list')]: listDependency,
+        ['#newContributions']: newContributions,
+      }) => continuation({
+        [listDependency]:
+          newContributions,
+      }),
+    },
+  ],
+});
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 65cc1b68..ce9f413c 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -18,7 +18,8 @@ import {
 } from '#yaml';
 
 import {withPropertyFromObject} from '#composite/data';
-import {withResolvedContribs} from '#composite/wiki-data';
+import {withRecontextualizedContributionList, withResolvedContribs}
+  from '#composite/wiki-data';
 
 import {
   exitWithoutDependency,
@@ -219,6 +220,10 @@ export class Track extends Thing {
         property: input.value('artistContribs'),
       }),
 
+      withRecontextualizedContributionList({
+        list: '#album.artistContribs',
+      }),
+
       exposeDependency({dependency: '#album.artistContribs'}),
     ],
 
@@ -254,6 +259,10 @@ export class Track extends Thing {
         property: input.value('trackCoverArtistContribs'),
       }),
 
+      withRecontextualizedContributionList({
+        list: '#album.trackCoverArtistContribs',
+      }),
+
       exposeDependency({dependency: '#album.trackCoverArtistContribs'}),
     ],