| 144 | const cache = new Map<PropertyKey, unknown>() |
| 145 | return new Proxy(keymap, { |
| 146 | get(target, prop) { |
| 147 | const value = Reflect.get(target, prop, target) |
| 148 | if (typeof value !== "function") return value |
| 149 | if (cache.has(prop)) return cache.get(prop) |
| 150 | const fn = ScopedKeymapMethods.has(prop) |
| 151 | ? (...args: unknown[]) => { |
| 152 | const dispose = (value as (...args: unknown[]) => unknown).apply(target, args) |
| 153 | return scope.track(typeof dispose === "function" ? (dispose as () => void) : undefined) |
| 154 | } |
| 155 | : (...args: unknown[]) => (value as (...args: unknown[]) => unknown).apply(target, args) |
| 156 | cache.set(prop, fn) |
| 157 | return fn |
| 158 | }, |
| 159 | }) |
| 160 | } |
| 161 | |