« 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.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.js
parent3cc050187760c758c4760121281ff9a7e0b626f5 (diff)
find, reverse: fr.bind + bindReverse
Diffstat (limited to 'src/find.js')
-rw-r--r--src/find.js41
1 files changed, 10 insertions, 31 deletions
diff --git a/src/find.js b/src/find.js
index d1435fb5..c7813e32 100644
--- a/src/find.js
+++ b/src/find.js
@@ -9,9 +9,11 @@ import * as fr from './find-reverse.js';
 
 import {
   tokenKey as findTokenKey,
+  boundData as boundFindData,
+  boundOptions as boundFindOptions,
 } from './find-reverse.js';
 
-export {findTokenKey};
+export {findTokenKey, boundFindData, boundFindOptions};
 
 function warnOrThrow(mode, message) {
   if (mode === 'error') {
@@ -284,9 +286,6 @@ export function findFindSpec(key) {
   return fr.findSpec(key, findReverseHelperConfig);
 }
 
-export const boundFindData = Symbol.for('find.boundFindData');
-export const boundFindOptions = Symbol.for('find.boundFindOptions');
-
 function findMixedHelper(config) {
   const
     keys = Object.keys(config),
@@ -415,33 +414,13 @@ export default fr.tokenProxy({
 // function. Note that this caches the arrays read from wikiData right when it's
 // called, so if their values change, you'll have to continue with a fresh call
 // to bindFind.
-export function bindFind(wikiData, opts1) {
-  const findSpecs = getAllFindSpecs();
-
-  const boundFindFns = {};
-
-  for (const [key, spec] of Object.entries(findSpecs)) {
-    if (!spec.bindTo) continue;
-
-    const findFn = findHelper(spec);
-    const thingData = wikiData[spec.bindTo];
-
-    boundFindFns[key] =
-      (opts1
-        ? (ref, opts2) =>
-            (opts2
-              ? findFn(ref, thingData, {...opts1, ...opts2})
-              : findFn(ref, thingData, opts1))
-        : (ref, opts2) =>
-            (opts2
-              ? findFn(ref, thingData, opts2)
-              : findFn(ref, thingData)));
-
-    boundFindFns[key][boundFindData] = thingData;
-    boundFindFns[key][boundFindOptions] = opts1 ?? {};
-  }
+export function bindFind(wikiData, opts) {
+  const boundFind = fr.bind(wikiData, opts, {
+    getAllSpecs: getAllFindSpecs,
+    prepareBehavior: findHelper,
+  });
 
-  boundFindFns.mixed = findMixed;
+  boundFind.mixed = findMixed;
 
-  return boundFindFns;
+  return boundFind;
 }