From 400026daec05541097a3541dae236ad5e073f81a Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Sun, 30 Mar 2025 23:28:03 +0700 Subject: [PATCH] feat(lib/utils/proxy): store targets --- lib/init/src/patches/proxy.ts | 4 ++-- lib/utils/src/proxy.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/init/src/patches/proxy.ts b/lib/init/src/patches/proxy.ts index 5b37c3e..b027021 100644 --- a/lib/init/src/patches/proxy.ts +++ b/lib/init/src/patches/proxy.ts @@ -4,7 +4,7 @@ */ export const _instances = new WeakSet() -// export const _targets = new WeakMap() +export const _targets = new WeakMap() const OriginalProxy = globalThis.Proxy globalThis.Proxy = new Proxy(OriginalProxy, { @@ -12,7 +12,7 @@ globalThis.Proxy = new Proxy(OriginalProxy, { // @ts-expect-error const prox = new OriginalProxy(...args) _instances.add(prox) - // _targets.set(prox, args[0]) + _targets.set(prox, args[0]) return prox }, }) diff --git a/lib/utils/src/proxy.ts b/lib/utils/src/proxy.ts index 6d55a3f..c7b0529 100644 --- a/lib/utils/src/proxy.ts +++ b/lib/utils/src/proxy.ts @@ -1,4 +1,4 @@ -import { _instances /* _targets */ } from '../../init/src/patches/proxy' +import { _instances, _targets } from '../../init/src/patches/proxy' /** * Returns whether the object is a proxy @@ -8,6 +8,6 @@ export function isProxy(obj: object) { return _instances.has(obj) } -// export function getProxyTarget(obj: object) { -// return _targets.get(obj) -// } +export function getProxyTarget(obj: object) { + return _targets.get(obj) +}