Re: [webcomponents] Move defineElement elsewhere? (#431)

FWIW, I've occasionally wished for a way to know what custom elements have been registered.

* When debugging a complex component-based app with multiple levels of module dependencies and other complications, it can be helpful to just get confirmation that a particular custom element has, in fact, being successfully registered.
* I've already hit cases where I wanted to provide a definition for a component if a definition hadn't already been registered. It's possible to just call createElement('foo-bar') and sniff the result, but it'd be nice to have a more deterministic way.
* Someday I'd like the debugger to be able list the currently-registered elements, let me jump to their declarations, etc.

While @rniwa didn't intend to suggest a feature, I actually think having window.customElements provide a list of registered elements would be pretty interesting. It could be a dictionary or Map of element names to classes, for example.

    class FooBar extends HTMLElement {...}
    window.customElements.defineElement('foo-bar', FooBar);
    window.customElements['foo-bar'] // returns FooBar

Note that there's no potential for conflict between the element registration methods and custom element names, since the element names have to include a hyphen.

---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/431#issuecomment-195602621

Received on Friday, 11 March 2016 23:31:42 UTC