Skip to content

Commit

Permalink
data: reverseAnnotatedReferenceList
Browse files Browse the repository at this point in the history
  • Loading branch information
towerofnix committed Nov 17, 2024
1 parent 89cf67d commit 6bcbe4f
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/data/composite/wiki-data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export {default as withResolvedContribs} from './withResolvedContribs.js';
export {default as withResolvedReference} from './withResolvedReference.js';
export {default as withResolvedReferenceList} from './withResolvedReferenceList.js';
export {default as withResolvedSeriesList} from './withResolvedSeriesList.js';
export {default as withReverseAnnotatedReferenceList} from './withReverseAnnotatedReferenceList.js';
export {default as withReverseContributionList} from './withReverseContributionList.js';
export {default as withReverseReferenceList} from './withReverseReferenceList.js';
export {default as withReverseSingleReferenceList} from './withReverseSingleReferenceList.js';
Expand Down
81 changes: 81 additions & 0 deletions src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js
Original file line number Diff line number Diff line change
@@ -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',
}),
],
});
1 change: 1 addition & 0 deletions src/data/composite/wiki-properties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export {default as flag} from './flag.js';
export {default as name} from './name.js';
export {default as referenceList} from './referenceList.js';
export {default as referencedArtworkList} from './referencedArtworkList.js';
export {default as reverseAnnotatedReferenceList} from './reverseAnnotatedReferenceList.js';
export {default as reverseContributionList} from './reverseContributionList.js';
export {default as reverseReferenceList} from './reverseReferenceList.js';
export {default as reverseSingleReferenceList} from './reverseSingleReferenceList.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {input, templateCompositeFrom} from '#composite';

import {exposeDependency} from '#composite/control-flow';
import {inputWikiData, withReverseAnnotatedReferenceList}
from '#composite/wiki-data';

export default templateCompositeFrom({
annotation: `reverseAnnotatedReferenceList`,

compose: false,

inputs: {
data: inputWikiData({allowMixedTypes: false}),
list: input({type: 'string'}),
},

steps: () => [
withReverseAnnotatedReferenceList({
data: input('data'),
list: input('list'),
}),

exposeDependency({dependency: '#reverseAnnotatedReferenceList'}),
],
});

0 comments on commit 6bcbe4f

Please sign in to comment.