Skip to content

How to monitor a complex object state? #2923

Answered by e111077
Linya-IronMan asked this question in Q&A
Discussion options

You must be logged in to vote

Lit does not have this out the box for performance reasons. Lit @property() asdf under the hood is essentially set asdf() {... this.requestUpdate('asdf', oldValue)} and a get 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.

class MyEl extends LitElement {
  @property({type: Object})
  @watch('account.email')
  user: User|null = null;
}

Back in the Polymer days we used Object.observe() which is now gone. Perhaps something else can be implemented using ES6 Proxies that call this.requstUpdate('user.account.email', oldValue)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Linya-IronMan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants