« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/reverse.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/reverse.js')
-rw-r--r--src/reverse.js17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/reverse.js b/src/reverse.js
index 0f235369..324cbabe 100644
--- a/src/reverse.js
+++ b/src/reverse.js
@@ -1,5 +1,13 @@
 import * as fr from './find-reverse.js';
 
+function reverseHelper(spec) {
+  const cache = new WeakMap();
+
+  return (thing, data) => {
+    return ({spec, from: thing, data: data.length});
+  };
+}
+
 const hardcodedReverseSpecs = {};
 
 const findReverseHelperConfig = {
@@ -28,5 +36,12 @@ export function findReverseSpec(key) {
 
 export default fr.tokenProxy({
   findSpec: findReverseSpec,
-  prepareBehavior: spec => from => ({spec, from}),
+  prepareBehavior: reverseHelper,
 });
+
+export function bindReverse(wikiData, opts) {
+  return fr.bind(wikiData, opts, {
+    getAllSpecs: getAllReverseSpecs,
+    prepareBehavior: reverseHelper,
+  });
+}