[w3c/webcomponents] Is there a way to retrieve the localName from a custom element constructor? (#566)

I've read the spec and I can't find any mention of how to get the localName of an element from the constructor. In v0 (I know, don't rely on old Blink) you could:

```js
const Ctor = document.registerElement('x-test', {
  prototype: Object.create(HTMLElement.prototype)
});

// x-test
console.log(Ctor.name);
```

In Chrome Canary this behaves as I'd expect:

```js
class Ctor extends HTMLElement {}
window.customElements.define('x-test', Ctor);

// Ctor
console.log(Ctor.name);
```

I can see why this is but I feel there's use cases for this. For example, when exporting a custom element constructor, consumers may need to know the name that it got registered with. In https://github.com/webcomponents/react-integration, we use the registered name in order to tell React the element it should create in the virtual DOM. Currently we have to construct the component and get the `tagName` from it.

A proposal for this may be to add a method to `CustomElementRegistry` which retrieves the name of the element when passed a constructor:

```js
// any getLocalName(Function constructor)
window.customElements.getLocalName(Ctor);
```

It could return `null` if not found, or the `localName` if found.

Thoughts?

-- 
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/566

Received on Wednesday, 14 September 2016 00:28:11 UTC