-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89cf67d
commit 6bcbe4f
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/data/composite/wiki-data/withReverseAnnotatedReferenceList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/data/composite/wiki-properties/reverseAnnotatedReferenceList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}), | ||
], | ||
}); |