I am trying to print out which nodes are being accessed via the getter by overriding my objects getter with a proxy. I am trying to basically test which parts of this large object are not being used by my application. The problem I am having is being able to add some way of identifying what a getters parents are. Here is what I have so far
function tracePropAccess(obj) {
return new Proxy(obj, {
get(target, propKey, receiver) {
console.log("Get fired on ", propKey);
return Reflect.get(target, propKey, receiver);
}
});
}
const testObj = {
a: 1,
b: {
a: "no",
b: "yes"
},
c: {
a: "green",
b: {
a: "blue",
b: "orange"
}
}
};
const tracer = tracePropAccess(testObj);
tracer.b.a;
tracer.a;
tracer.c.c.a;
This works great in showing me the prop key - however it only the key from the first level. I am not sure how to approach this with this proxy as this single function overrides all the proxies in the provided object. Is there any way to possibly pass in an objects parents/children? Possibly I am approaching this incorrectly as well - so I am looking for any input. Thanks!