« get me outta code hell

find, reverse: fr.bind + bindReverse - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/find-reverse.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-01-11 17:05:25 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-01-11 17:05:25 -0400
commit13f91d9ff89dcf0ca8b7895b21b1e0cf43df38f9 (patch)
treef25a02cd225c505ec8d1b16f5f3b59e77f8fd4a8 /src/find-reverse.js
parent3cc050187760c758c4760121281ff9a7e0b626f5 (diff)
find, reverse: fr.bind + bindReverse
Diffstat (limited to 'src/find-reverse.js')
-rw-r--r--src/find-reverse.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/find-reverse.js b/src/find-reverse.js
index 5f8e2100..1e897a5c 100644
--- a/src/find-reverse.js
+++ b/src/find-reverse.js
@@ -96,4 +96,38 @@ export function tokenProxy({
   });
 }
 
+export function bind(wikiData, opts1, {
+  getAllSpecs,
+  prepareBehavior,
+}) {
+  const specs = getAllSpecs();
+
+  const bound = {};
+
+  for (const [key, spec] of Object.entries(specs)) {
+    if (!spec.bindTo) continue;
+
+    const behavior = prepareBehavior(spec);
+    const thingData = wikiData[spec.bindTo];
+
+    bound[key] =
+      (opts1
+        ? (ref, opts2) =>
+            (opts2
+              ? behavior(ref, thingData, {...opts1, ...opts2})
+              : behavior(ref, thingData, opts1))
+        : (ref, opts2) =>
+            (opts2
+              ? behavior(ref, thingData, opts2)
+              : behavior(ref, thingData)));
+
+    bound[key][boundData] = thingData;
+    bound[key][boundOptions] = opts1 ?? {};
+  }
+
+  return bound;
+}
+
 export const tokenKey = Symbol.for('find.tokenKey');
+export const boundData = Symbol.for('find.boundData');
+export const boundOptions = Symbol.for('find.boundOptions');