Skip to content

Commit

Permalink
added get listener and removed ownkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
overthemike committed Sep 1, 2024
1 parent e301ec8 commit ab1c462
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,17 @@ export const schema = <T extends ZodType<any>>(
})
}

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<T>
Expand Down

0 comments on commit ab1c462

Please sign in to comment.