Re: [w3c/webcomponents] A way to detect if a custom element was constructed during customElements.define call? (#790)

> The reason is, because I'm finding that if I define elements **_after_** they have already been parsed, then creating a `MutationObserver` in the constructor _does not_ observe `childList` because the nodes that are being upgraded already have the children (no DOM mutation happened).

An upgrade can happen with children in other scenarios, too. Why not just check to see if the element already has children in the constructor?

```javascript
class MyEl extends HTMLElement {
  constructor() {
    super();
    if (this.children.length) {
      console.log('has children when upgraded');
    }
  }
}
```

-- 
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/790#issuecomment-460950445

Received on Wednesday, 6 February 2019 09:11:53 UTC