You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is useful to frameworks that are built to work with/on top of web components in 2 ways that tie into each other.
They can validate and error if a particular class has not defined a localName before an error is thrown from instantiating the class.
They can auto generate localNames at mount time(when found to be undefined)
The ability to know whether a component has defined a localName allows framework authors to create API's that can consume web component classes in a way that relegates the need to define a components localName when declaring your component to being optional.
One possible way to support this pattern is for frameworks to wrap the mount/instantiating in a try-catch, and auto-generate a localName from the classes name in the catch block when instantiating throws an error.
A second method might be to auto-generate an obscure localName regardless of if one has been defined outside of what the framework can pick up from.
Alternative API
The problems stated above could be solved in a similar fashion to customElements.hasLocalName by exposing an API that returns a components defined localName.
I could not find any documentation on a method to check whether a particular class has defined its localName
customElement.define(localName, Class)
.customElements.hasLocalName
This is useful to frameworks that are built to work with/on top of web components in 2 ways that tie into each other.
The ability to know whether a component has defined a localName allows framework authors to create API's that can consume web component classes in a way that relegates the need to define a components localName when declaring your component to being optional.
Current Landscape.
One possible way to support this pattern is for frameworks to wrap the mount/instantiating in a
try-catch
, and auto-generate a localName from the classes name in the catch block when instantiating throws an error.A second method might be to auto-generate an obscure localName regardless of if one has been defined outside of what the framework can pick up from.
Alternative API
The problems stated above could be solved in a similar fashion to
customElements.hasLocalName
by exposing an API that returns a components defined localName.The text was updated successfully, but these errors were encountered: