Skip to content

Commit b0444ca

Browse files
committed
data: reverseSingleReferenceList
1 parent a46db43 commit b0444ca

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

src/data/composite/wiki-data/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ export {default as withResolvedReference} from './withResolvedReference.js';
1919
export {default as withResolvedReferenceList} from './withResolvedReferenceList.js';
2020
export {default as withReverseContributionList} from './withReverseContributionList.js';
2121
export {default as withReverseReferenceList} from './withReverseReferenceList.js';
22+
export {default as withReverseSingleReferenceList} from './withReverseSingleReferenceList.js';
2223
export {default as withThingsSortedAlphabetically} from './withThingsSortedAlphabetically.js';
2324
export {default as withUniqueReferencingThing} from './withUniqueReferencingThing.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Like withReverseReferenceList, but for finding all things which reference
2+
// the current thing by a property that contains a single reference, rather
3+
// than within a reference list.
4+
5+
import withReverseList_template from './helpers/withReverseList-template.js';
6+
7+
import {input} from '#composite';
8+
9+
import {withMappedList} from '#composite/data';
10+
11+
export default withReverseList_template({
12+
annotation: `withReverseSingleReferenceList`,
13+
14+
propertyInputName: 'ref',
15+
outputName: '#reverseSingleReferenceList',
16+
17+
customCompositionSteps: () => [
18+
{
19+
dependencies: [input('data')],
20+
compute: (continuation, {
21+
[input('data')]: data,
22+
}) => continuation({
23+
['#referencingThings']:
24+
data,
25+
}),
26+
},
27+
28+
// This map wraps each referenced thing in a single-item array.
29+
// Each referencing thing references exactly one thing, if any.
30+
{
31+
dependencies: [input('ref')],
32+
compute: (continuation, {
33+
[input('ref')]: ref,
34+
}) => continuation({
35+
['#singleReferenceMap']:
36+
thing =>
37+
(thing[ref]
38+
? [thing[ref]]
39+
: []),
40+
}),
41+
},
42+
43+
withMappedList({
44+
list: '#referencingThings',
45+
map: '#singleReferenceMap',
46+
}).outputs({
47+
'#mappedList': '#referencedThings',
48+
}),
49+
],
50+
});

src/data/composite/wiki-properties/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export {default as name} from './name.js';
2121
export {default as referenceList} from './referenceList.js';
2222
export {default as reverseContributionList} from './reverseContributionList.js';
2323
export {default as reverseReferenceList} from './reverseReferenceList.js';
24+
export {default as reverseSingleReferenceList} from './reverseSingleReferenceList.js';
2425
export {default as simpleDate} from './simpleDate.js';
2526
export {default as simpleString} from './simpleString.js';
2627
export {default as singleReference} from './singleReference.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {input, templateCompositeFrom} from '#composite';
2+
3+
import {exposeDependency} from '#composite/control-flow';
4+
import {inputWikiData, withReverseSingleReferenceList} from '#composite/wiki-data';
5+
6+
export default templateCompositeFrom({
7+
annotation: `reverseSingleReferenceList`,
8+
9+
compose: false,
10+
11+
inputs: {
12+
data: inputWikiData({allowMixedTypes: false}),
13+
ref: input({type: 'string'}),
14+
},
15+
16+
steps: () => [
17+
withReverseSingleReferenceList({
18+
data: input('data'),
19+
ref: input('ref'),
20+
}),
21+
22+
exposeDependency({dependency: '#reverseSingleReferenceList'}),
23+
],
24+
});

0 commit comments

Comments
 (0)