diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-11-16 15:41:31 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-11-17 13:40:01 -0400 |
commit | 6bcbe4f3489bafff4a78f87e030c08db734af021 (patch) | |
tree | 94715c3579636f0aa1ea2756ebe8b98989980745 /src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js | |
parent | 89cf67d4348d4ac43df158b265fdac4e48cfe03c (diff) |
data: reverseAnnotatedReferenceList
Diffstat (limited to 'src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js')
-rw-r--r-- | src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js b/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js new file mode 100644 index 00000000..168b68c0 --- /dev/null +++ b/src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js @@ -0,0 +1,81 @@ +// Analogous implementation for withReverseReferenceList, for annotated +// references. +// +// Unlike withReverseContributionList, this composition is responsible for +// "flipping" the directionality of references: in a forward reference list, +// `thing` points to the thing being referenced, while here, it points to the +// referencing thing. + +import withReverseList_template from './helpers/withReverseList-template.js'; + +import {input} from '#composite'; +import {stitchArrays} from '#sugar'; + +import { + withFlattenedList, + withMappedList, + withPropertyFromList, + withStretchedList, +} from '#composite/data'; + +export default withReverseList_template({ + annotation: `withReverseAnnotatedReferenceList`, + + propertyInputName: 'list', + outputName: '#reverseAnnotatedReferenceList', + + customCompositionSteps: () => [ + withPropertyFromList({ + list: input('data'), + property: input('list'), + }).outputs({ + '#values': '#referenceLists', + }), + + withPropertyFromList({ + list: '#referenceLists', + property: input.value('length'), + }), + + withFlattenedList({ + list: '#referenceLists', + }).outputs({ + '#flattenedList': '#references', + }), + + withStretchedList({ + list: input('data'), + lengths: '#referenceLists.length', + }).outputs({ + '#stretchedList': '#things', + }), + + withPropertyFromList({ + list: '#references', + property: input.value('annotation'), + }).outputs({ + '#references.annotation': '#annotations', + }), + + { + dependencies: ['#things', '#annotations'], + compute: (continuation, { + ['#things']: things, + ['#annotations']: annotations, + }) => continuation({ + ['#referencingThings']: + stitchArrays({ + thing: things, + annotation: annotations, + }), + }), + }, + + withMappedList({ + list: '#references', + map: input.value(reference => [reference.thing]), + }).outputs({ + '#mappedList': '#referencedThings', + }), + ], +}); |