Re: [w3c/webcomponents] [idea] Allowing custom element registrations on per-shadow-root basis. (#488)

Idea: what if registrations are loose? So, for example, `let myForm = new MyForm` just instantiates the element, but there is no tagName associated with it yet. When `myForm` gets attached into, for example, a shadow root with `MyForm` registered to the `my-form` tagName, then the instance gains that name while in that shadow node tree, and therefore selectors that target `my-form` within that node tree would properly target that instance.

As for document fragments, maybe they too can have a loose registry in the same fashion.

Element instances would then be able to be detached and and attached into new node trees, and would take on new tagNames. The element name then becomes sort of like a label, telling the node tree "Hey, whenever an element that is `instanceof MyForm` is in this tree, we refer to it as `my-form` in the markup, and `my-form` when selecting elements by tag name with CSS."

The name of the `MyForm` instance would be unknown until the node is placed in the context of a tree, and in that case the tagName is simply a way to refer to the instance while the instance lives in that tree.

Instances of a Custom Element don't really actually need to know what they are referred to as in order to be what they are. For example, my mom in my family tree calls me one thing, but my friends in one of my friend trees might call me something else, but in the end, I am me.

Could that work?

> There are bigger problems, e.g. how CSS selectors or the HTML parser could work given how they both assume a single global namespace

This would have to change a little, but that's okay because this would be a hidden implementation detail and would not affect end usage. The parser can look up the registry depending on which tree the parsing is happening for. For example, setting `innerHTML` on a shadow root would cause the parser to use that root's registry; similar with CSS.

---
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/488#issuecomment-228980850

Received on Tuesday, 28 June 2016 08:09:16 UTC