How can I handle all traps for ownKeys in a nested object?
I only know how to handle one level deep object:
function wrap(obj, fn) {
var handler = {
ownKeys(target) {
fn(target)
return target
}
}
return new Proxy(obj, handler)
}
var origObj = {
a: {
b: {
c: 0
}
}
}
var wrappedObj = wrap(origObj, console.log)
Object.keys(wrappedObj) // => actual = expected: { a: { b: { c: 0 } } }
Object.keys(wrappedObj.a) // => actual: not working, expected: { b: { c: 0 } }
Object.keys(wrappedObj.a.b) // => actual: not working, expected: { c: 0 }
edit 1:
If I try to wrap each inner object (from this answer) then it logs all steps not just the last one. By "all steps" I mean the inner process of the proxy which goes through the whole nested object so it fires fn(target) multiple times but I want to fire it only once.
edit 2:
So it looks that the problem is with the node environmnent (node version 8.1.4) where proxy looks broken. In the chrome console is everything ok.

origObjis proxied, the inner objects are not.targetinside the proxy.