diff options
Diffstat (limited to 'src/reverse.js')
-rw-r--r-- | src/reverse.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/reverse.js b/src/reverse.js index 59790219..9b642e39 100644 --- a/src/reverse.js +++ b/src/reverse.js @@ -19,15 +19,22 @@ function reverseHelper(spec) { cache.set(data, cacheRecord); // Get the referencing and referenced things. This is the meat of how - // one reverse spec is different from another. + // one reverse spec is different from another. If the spec includes a + // 'tidy' step, use that to finalize the referencing things, the way + // they'll be recorded as results. - const referencingThings = + const interstitialReferencingThings = (spec.bindTo === 'wikiData' ? spec.referencing(data) : data.flatMap(thing => spec.referencing(thing))); const referencedThings = - referencingThings.map(thing => spec.referenced(thing)); + interstitialReferencingThings.map(thing => spec.referenced(thing)); + + const referencingThings = + (spec.tidy + ? interstitialReferencingThings.map(thing => spec.tidy(thing)) + : interstitialReferencingThings); // Actually fill in the cache record. Since we're building up a *reverse* // reference list, track connections in terms of the referenced thing. |