diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-03-06 13:41:38 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-06-12 17:26:34 -0300 |
commit | 323c8df744ea58e52f107e4a85589e8e338998cd (patch) | |
tree | b049b197e31b8251b0ab7d0f9f694708edba532c /src/data/composite/wiki-data | |
parent | 06303dc8585add99110160a69c6d9c818a9b5ded (diff) |
data: withRecontextualizedContributionList
Diffstat (limited to 'src/data/composite/wiki-data')
-rw-r--r-- | src/data/composite/wiki-data/index.js | 1 | ||||
-rw-r--r-- | src/data/composite/wiki-data/withRecontextualizedContributionList.js | 77 |
2 files changed, 78 insertions, 0 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, + }), + }, + ], +}); |