leverage getRootNode()
for referencing Shadow DOM based parent node reference in JSX output
#109
Labels
0.11.0
enhancement
Improvement to existing functionality
JSX
question
Further information is requested
Milestone
Type of Change
Summary
So stumbled upon
getRootNode()
in MDN and this seems this may allow us to make the output of our serialization process a little more compact when handlingthis
references to hosts (components) when calling event handlers or otherwise referencing state that lives at the Custom Element (definition)class
level.Details
For example, WCC's JSX let's you write something like this
Which because of how
this
works, means you would be referencingincrement
on the<button>
, not<wcc-counter>
. So get that correct chain of references to the host element (<wcc-counter>
) WCC / JSX recursively walks the HTML structure to come up with something like thisBUT, it seems like with
getRootNode
, we could sidestep all that and can just referencethis.getRootNode()
directly?Presumably this only works with a Shadow Root, as initial testing seemed to indicate that in a Light DOM context, the "root" node was actually the document, or something like that. So should play around with this first in the browser a bit at least just to get a feel for it.
The text was updated successfully, but these errors were encountered: