Skip to content
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

Fixes #965 as long as requestUpdate is called before setting other properties #987

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sorvell
Copy link
Member

@sorvell sorvell commented May 4, 2020

It is now possible to set a computed reflecting property in another property's setter as long as requestUpdate is called before setting the computed property. Previous to this change, the following construction would fail:

// snippit from element class
@property({type: String, reflect: true}) b: string;

@property()
set a(value) {
  const oldValue = this.a;
  this._a = value;
  this.b = 'b';
  this.requestUpdate('a', oldValue);
}

// user code
el.setAttribute('a', 'a');
await el.updateComplete;
console.assert(el.getAttribute('b') == 'b') // false =(

With this change, the above code will still fail but it can be trivially changed so that it works by ensuring the other property is set after calling requestUpdate.

// updated snippit from class with everything the same except 
// where requestUpdate is called in the setter
set a(value) {
  const oldValue = this.a;
  this._a = value; 
  this.requestUpdate('a', oldValue); // ok to set a reflecting property after this
  this.b = 'b';
}

// user code
el.setAttribute('a', 'a');
await el.updateComplete;
console.assert(el.getAttribute('b') == 'b') // true =)

Steven Orvell added 4 commits May 4, 2020 15:17
It is now possible to set a computed reflecting property in another property's setter as long as `requestUpdate` is called before setting the computed property.

Note, this does require a slightly user code modification to address #965 but it addresses the use case without degrading performance by adding per-property tracking (which is the other alternative).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants