- From: Andrea Giammarchi <notifications@github.com>
- Date: Sat, 20 Oct 2018 02:11:32 -0700
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Saturday, 20 October 2018 09:11:53 UTC
@franktopel it's useful for empty nodes with shadow dom, and not much else indeed.
With `parsedCallback` you can setup sure that attributes are there as well.
Meanwhile, if you react to `attributeChangedCallback`, if `this.parsed` is false you should queue the operations if important for the component state.
```js
const attributeChanged = new WeakMap;
class MyEl extends HTMLParsedElement {
  parsedCallback() {
    // setup the node
    const changes = attributeChanged.get(this);
    if (changes) {
      attributeChanged.delete(this);
      changes.forEach(args => this. attributeChangedCallback.apply(this, args));
    }
  }
  attributeChangedCallback(name, oldVal, newVal) {
    if (!this.parsed) {
      const changes = attributeChanged.get(this) || [];
      changes.push([name, oldVal, newVal]);
      if (changes.length === 1)
        attributeChanged.set(this, changes);
      return;
    }
    // the rest of the code
  }
  connectedCallback() {
    // here you can safely add listeners
    // or set own component properties
    this.live = true;
  }
  disconnectedCallback() {
    // here you can safely remove listeners
    this.live = false;
  }
}
```
-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/551#issuecomment-431563622
Received on Saturday, 20 October 2018 09:11:53 UTC