diff options
Diffstat (limited to 'src/find-reverse.js')
-rw-r--r-- | src/find-reverse.js | 34 |
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'); |