« get me outta code hell

reverse: tidy step - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-01-11 17:34:29 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-01-11 17:34:29 -0400
commit1cc21e130e691d79677c62362a17070597e1ee93 (patch)
treeb817e0dbce61405b61e8cd4b4d2fe510e6174bc4
parentedad98e0408571e4c6cabceaa5234510cefaaea5 (diff)
reverse: tidy step
-rw-r--r--src/reverse.js13
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.