From 1cc21e130e691d79677c62362a17070597e1ee93 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 11 Jan 2025 17:34:29 -0400 Subject: reverse: tidy step --- src/reverse.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') 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. -- cgit 1.3.0-6-gf8a5