Re: [w3c/webcomponents] [idea] childConnectedCallback and childDisconnectedCallback (#550)

I made a pen based on the [MDN example](https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath):

https://codepen.io/trusktr/pen/66d328c9378e850f6419086d0624ead7

Anywho, turns out this is only good in Custom Elements, as we can at most enforce out own elements emit the events.

Originally I mentioned:

> `MutationObserver` _will not fire during parsing_

@rniwa [pointed out](https://github.com/w3c/webcomponents/issues/787#issuecomment-458456606) that if the `MutationObserver` is created in `connectedCallback`, then it doesn't fire for children during parsing. The observer has to be created in the constructor.

I wanted to create an observer in `connectedCallback`, then clean it up (`.disconnect()` it) in `disconnectedCallback`, so as to keep things cleaned up when done using them.

I eventually figured the pattern to conditionally create the observer either in the `constructor` or in `connectedCallback` as needed, while cleaning up in `disconnectedCallback`. Here's [that example](https://github.com/w3c/webcomponents/issues/787#issuecomment-459829842).

Then I asked about [being able to check `if (isParsing) {}` or similar](https://github.com/w3c/webcomponents/issues/789), which I haven't investigated yet to see if it is useful in making the previous example cleaner.

-- 
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/550#issuecomment-459830917

Received on Friday, 1 February 2019 19:01:09 UTC