From 301ed2a12f4716a85359b6cb50462e415539553f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 17 Jan 2024 13:58:47 -0400 Subject: data: stub reverseContributionList --- src/data/composite/wiki-data/index.js | 1 + .../wiki-data/withReverseContributionList.js | 45 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/data/composite/wiki-data/withReverseContributionList.js (limited to 'src/data/composite/wiki-data') diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js index a2ff09d8..d64930e1 100644 --- a/src/data/composite/wiki-data/index.js +++ b/src/data/composite/wiki-data/index.js @@ -11,5 +11,6 @@ export {default as withParsedCommentaryEntries} from './withParsedCommentaryEntr export {default as withResolvedContribs} from './withResolvedContribs.js'; export {default as withResolvedReference} from './withResolvedReference.js'; export {default as withResolvedReferenceList} from './withResolvedReferenceList.js'; +export {default as withReverseContributionList} from './withReverseContributionList.js'; export {default as withReverseReferenceList} from './withReverseReferenceList.js'; export {default as withThingsSortedAlphabetically} from './withThingsSortedAlphabetically.js'; diff --git a/src/data/composite/wiki-data/withReverseContributionList.js b/src/data/composite/wiki-data/withReverseContributionList.js new file mode 100644 index 00000000..71e3c1a8 --- /dev/null +++ b/src/data/composite/wiki-data/withReverseContributionList.js @@ -0,0 +1,45 @@ +// Analogous implementation for withReverseReferenceList, but contributions. +// +// This implementation uses a global cache (via WeakMap) to attempt to speed +// up subsequent similar accesses. Reverse contribution lists are the most +// costly in live-dev-server, but we intend to expand the impelemntation here +// to reverse reference lists in general later on. + +import {input, templateCompositeFrom} from '#composite'; + +import {exitWithoutDependency} from '#composite/control-flow'; + +import inputWikiData from './inputWikiData.js'; + +export default templateCompositeFrom({ + annotation: `withReverseContributionList`, + + inputs: { + data: inputWikiData({allowMixedTypes: false}), + list: input({type: 'string'}), + }, + + outputs: ['#reverseContributionList'], + + steps: () => [ + exitWithoutDependency({ + dependency: input('data'), + value: input.value([]), + mode: input.value('empty'), + }), + + { + dependencies: [input.myself(), input('data'), input('list')], + + compute: (continuation, { + [input.myself()]: myself, + [input('data')]: data, + [input('list')]: list, + }) => + continuation({ + ['#reverseContributionList']: + data.filter(thing => thing[list].some(({who}) => who === myself)), + }), + }, + ], +}); -- cgit 1.3.0-6-gf8a5