From 323c8df744ea58e52f107e4a85589e8e338998cd Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 6 Mar 2024 13:41:38 -0400 Subject: data: withRecontextualizedContributionList --- src/data/composite/wiki-data/index.js | 1 + .../withRecontextualizedContributionList.js | 77 ++++++++++++++++++++++ src/data/things/track.js | 11 +++- 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/data/composite/wiki-data/withRecontextualizedContributionList.js (limited to 'src') 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'}), ], -- cgit 1.3.0-6-gf8a5