Re: [WICG/webcomponents] Need a callback for when children changed or parser finished parsing children (#809)

> To me it seems to reliably access children in `connectedCallback`, one has to check for both existing children (which is the case when the element is appended to the DOM via `.innerHTML` or similar methods like Vue does it), and for regular DOM content where the children will be available after a `childList` mutation. [Related demos](https://github.com/43081j/eslint-plugin-wc/pull/130#issuecomment-1979843442).
> 
> ```js
> connectedCallback() {
>   if (this.children.length) 
>     // access this.children
>   } else {
>     const observer = new MutationObserver(() => {
>       observer.disconnect();
>       // access this.children
>     }).observe(this, {childList: true});
>   } 
> }
> ```
> 
> Honstly, it seems way to much boilerplate for such a simple and common use case.

Say a component has many children, is there any chance the parser may connect the component after parsing some of the children, i.e. not all of them. It appears to this code assumes that all the children exist, or none of them at the time the code runs. (I am not sure if this is the case?).

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/809#issuecomment-2028865159
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/809/2028865159@github.com>

Received on Sunday, 31 March 2024 18:42:04 UTC