Lifecycle Event Bus #3286
waldronmatt
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Emitting events for every lifecycle is going to be expensive and slow down rendering. Hopefully you don't need to access a child's shadowRoot that often, and when you do you can frame this as an API on the child component. Like |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
On rare occasions I've needed to access the renderRoot of child components nested inside a parent shadowRoot. However, using the parent component's lifecycle methods doesn't guarantee access to child renderRoots - which I think is similar to this issue here WICG/webcomponents#551
To overcome this at my workplace, I created a simple mixin imported in every component that emits a custom event when one of the lifecycle events trigger. This has been proving great, specifically in situations where I have a custom app that wants to do something when a child component is connected to the DOM or even when an update is complete. Additionally, this has been reliable for guaranteeing access to renderRoot.
I'd like to hear the Lit team's thoughts on this, as I didn't see this approach documented. Is this a good/bad approach and is this something the team has considered? Much appreciated.
mixin.ts
child.ts
parent.ts
Beta Was this translation helpful? Give feedback.
All reactions