diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-03-06 13:41:38 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-06-18 22:56:01 -0300 |
commit | a5a31d5bf669fcb579d07c069a97f8945b743407 (patch) | |
tree | cbdaa0cd001816e52429d535ebd6014caa7e8343 /src/data/composite/wiki-data | |
parent | cca401d4b00c187f069eef25336d2364fb8d448e (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, + }), + }, + ], +}); |