-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make class fields observable #79
Comments
var base = new Proxy({},{
defineProperty(){
console.log("hit")
}
});
var obj = Object.create(base);
Object.defineProperty(obj, "foo", {value: "abc"}) |
This is prevented by tc39/proposal-class-fields#151 (comment) I wrote up a bit on why in that thread: tc39/proposal-class-fields#151 (comment) |
I think we could do this with class HelloWorld extends StacheElement {
static view = `<h1>Hello {{this.subject}}</h1>`;
subject = "World";
}
customElements.define("hello-world", HelloWorld); |
Solution BrainStormParsingCould we parse? class Obj3 {
foo = "bar"
constructor(){
}
}
Obj3.toString() // -> includes `foo = "bar"` Call a methodWe could ask folks to call a method: class HelloWorld extends StacheElement {
static view = `<h1>Hello {{this.subject}}</h1>`;
subject = "World";
constructor(){
super();
this.checkForProps();
}
} Check for these props in lifecyclesLike calling a method, we could check for these properties in the lifecycle methods. This would mean that Post initialization hookIf there was a way to capture when Decorators could help here, we could make sure the final constructor has some "completion" code. Overwrite Object.defineProperty
Wait for decoratorshttps://github.com/tc39/proposal-decorators#set class HelloWorld extends StacheElement {
static view = `<h1>Hello {{this.subject}}</h1>`;
@set subject = "World";
} |
For For If that works though, maybe we should just do the same in |
I think the For ObservableObject/ObservableArray, however, the "proxy instance" idea would have a few downsides.
|
Can you elaborate on the reasons for #3? |
Our |
For ObservableObject/ObservableArray, could we also do it in |
Currently |
We don't ever |
@matthewp (not saying we should do this), but we could make a "weak" seal ... essentially allow |
We just found another issue this would fix. If you set a property on an element instance before it is upgraded (before It's not incredibly likely that people will do this, but it should be possible. |
@cherifGsoul for
We should warn for the
|
We should eventually make this work:
The text was updated successfully, but these errors were encountered: