How to monitor a complex object state? #2923
-
The feature I hoped is like @Watch("target")
targetChange() { }
@Watch("target.name")
targetNameChange() { } I find a similar feature at But It can only monitor the whole object. Is there any function I want ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Lit does not have this out the box for performance reasons. Lit Though there is nothing stopping you from writing your own class MyEl extends LitElement {
@property({type: Object})
@watch('account.email')
user: User|null = null;
} Back in the Polymer days we used |
Beta Was this translation helpful? Give feedback.
Lit does not have this out the box for performance reasons. Lit
@property() asdf
under the hood is essentiallyset asdf() {... this.requestUpdate('asdf', oldValue)}
and aget asdf() {return this.__asdf}
. This is why setting a specific property won't trigger a change in lit.Though there is nothing stopping you from writing your own
@watch
directive. e.g.Back in the Polymer days we used
Object.observe()
which is now gone. Perhaps something else can be implemented using ES6 Proxies that callthis.requstUpdate('user.account.email', oldValue)