class Foo {
@tracked bar;
get baz() {
return this.bar;
}
}
let foo = new Foo();
In order to make this work, we need to know that bar
is a dependency of baz
when we access foo.baz
. Currently, we know this because bar
is instrumented.
In order to know this with proxies, we must not only wrap foo
in a proxy, we
must recursively wrap it in a proxy. Otherwise, baz
is a black box, we have
no idea what it accessed:
class Foo {
bar;
get baz() {
return this.bar;
}
}
let foo = new Foo();
let proxy = new Proxy(foo, {
get(target, key) {
let getter = Object.getOwnPropertyDescriptor(foo, key).get;
return get.call(proxy);
}
});
Every access to this
must be watched, even internally. Now, if we add a
private field internally, we break:
class Foo {
#bar;
get baz() {
return this.#bar;
}
}
let foo = new Foo();
let proxy = new Proxy(foo, {
get(target, key) {
let getter = Object.getOwnPropertyDescriptor(foo, key).get;
return get.call(proxy);
}
});
foo.baz; // ERROR