From ab1c4622f4f67d4fe5c2cff59c1bcc1346eb92fb Mon Sep 17 00:00:00 2001 From: Michael Sweeney Date: Sat, 31 Aug 2024 22:32:14 -0700 Subject: [PATCH] added get listener and removed ownkeys --- src/index.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index f5444ea..d56636b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -105,15 +105,17 @@ export const schema = >( }) } - Reflect.ownKeys(target).forEach((key) => { - if (isObject(target[key])) { - const newPath = parentPath.concat(key) - pathList.set(target[key], newPath) - createProxy(target[key], newPath) - } - }) - return new Proxy(target, { + get(target, prop, receiver) { + const value = Reflect.get(target, prop, receiver) + if (isObject(value)) { + const newPath = parentPath.concat(prop) + pathList.set(value, newPath) + return createProxy(value, newPath) + } else { + return value + } + }, set(target, prop, value, receiver) { const originalObject = schemaMeta.get(zodSchema)! .initialState as z.infer