From 13f91d9ff89dcf0ca8b7895b21b1e0cf43df38f9 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 11 Jan 2025 17:05:25 -0400 Subject: find, reverse: fr.bind + bindReverse --- src/reverse.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/reverse.js') 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, + }); +} -- cgit 1.3.0-6-gf8a5