-
Notifications
You must be signed in to change notification settings - Fork 391
Description
The following issues need APIs which should be used by custom element authors and should not be used by custom element users.
- Need callback for form submit data (#187)
- Custom pseudo-classes for host elements via shadow roots (:state) (#738)
At the March F2F we came up with one idea. However using ShadowRoot for such APIs looks very weird to me and I'd like to discuss it again.
Candidates:
-
ShadowRoot
Pros: Usually only custom element implementation knows the instance ofShadowRootwhich is used to implement the custom element. It's difficult for custom element users to get aShadowRootinstance created by a custom element implementation [1]
Cons:ShadowRootis an interface for tree-encapsulation. Adding features unrelated to tree-encapsulation looks like a design defect. We should not makeShadowRoota kitchen sink.
Cons: Not all custom element implementations needShadowRoot. For example, a checkbox custom element won't needShadowRoot. Creating unnecessaryShadowRootfor such APIs is not reasonable.
Cons: If a custom element implementation uses noShadowRoot, a custom element user can callelement.attachShadow()to get aShadowRootinstance, and thus get access to these private APIs. -
new Something(customElement)
It throws if users try to create it for the same element twice. It throws if the constructor is called with non-custom elements. The interfaceSomethingis called as ElementStates in Custom pseudo-classes for host elements via shadow roots (:state) #738, and called as HTMLElementPrimitives in Need callback for form submit data #187.
Pros:ShadowRootwon't have unrelated APIs.
Pros: Usually only custom element implementation knows the instance ofSomething. It's difficult for custom element users to get aSomethinginstance created by a custom element implementation [1]
Cons: If a custom element implementation uses noSomething, a custom element user can callnew Something(element)successfully to get aSomethinginstance. -
Deliver a
Somethinginstance by a custom element callback
See Need callback for form submit data #187 (comment) for more details.
Pros:ShadowRootwon't have unrelated APIs.
Pros: Custom element users can not create aSomethinginstance unlike other two candidates.
Pros: It's difficult for custom element users to get aSomethinginstance delivered to a custom element [1]
Cons: UA implementation would need larger code for a new callback, compared to the other two candidates.
IMO, the second one or the third one is much better than the first one.
@annevk @domenic @rniwa @trusktr What do you think?
[1] If a custom element implementation stores a ShadowRoot / Something instance to this.foo_, a custom element user can get the instance by accessing yourElement.foo_. There are some techniques to avoid such casual access.