| 212 | const cache = new Map<string, any>() |
| 213 | |
| 214 | function createSelectedProxy(path: Array<string>): any { |
| 215 | const pathKey = path.join(`.`) |
| 216 | if (cache.has(pathKey)) { |
| 217 | return cache.get(pathKey) |
| 218 | } |
| 219 | |
| 220 | const proxy = new Proxy({} as any, { |
| 221 | get(target, prop, receiver) { |
| 222 | if (prop === `__refProxy`) return true |
| 223 | if (prop === `__path`) return [`$selected`, ...path] |
| 224 | if (prop === `__type`) return undefined |
| 225 | if (typeof prop === `symbol`) return Reflect.get(target, prop, receiver) |
| 226 | |
| 227 | const newPath = [...path, String(prop)] |
| 228 | return createSelectedProxy(newPath) |
| 229 | }, |
| 230 | |
| 231 | has(target, prop) { |
| 232 | if (prop === `__refProxy` || prop === `__path` || prop === `__type`) |
| 233 | return true |
| 234 | return Reflect.has(target, prop) |
| 235 | }, |
| 236 | |
| 237 | ownKeys(target) { |
| 238 | return Reflect.ownKeys(target) |
| 239 | }, |
| 240 | |
| 241 | getOwnPropertyDescriptor(target, prop) { |
| 242 | if (prop === `__refProxy` || prop === `__path` || prop === `__type`) { |
| 243 | return { enumerable: false, configurable: true } |
| 244 | } |
| 245 | return Reflect.getOwnPropertyDescriptor(target, prop) |
| 246 | }, |
| 247 | }) |
| 248 | |
| 249 | cache.set(pathKey, proxy) |
| 250 | return proxy |
| 251 | } |
| 252 | |
| 253 | const wrappedSelectedProxy = createSelectedProxy([]) |
| 254 | |