{"action":"created","issue":{"url":"https://api.github.com/repos/w3c/webcomponents/issues/566","repository_url":"https://api.github.com/repos/w3c/webcomponents","labels_url":"https://api.github.com/repos/w3c/webcomponents/issues/566/labels{/name}","comments_url":"https://api.github.com/repos/w3c/webcomponents/issues/566/comments","events_url":"https://api.github.com/repos/w3c/webcomponents/issues/566/events","html_url":"https://github.com/w3c/webcomponents/issues/566","id":176784759,"number":566,"title":"Is there a way to retrieve the localName from a custom element constructor?","user":{"login":"treshugart","id":136556,"avatar_url":"https://avatars3.githubusercontent.com/u/136556?v=4","gravatar_id":"","url":"https://api.github.com/users/treshugart","html_url":"https://github.com/treshugart","followers_url":"https://api.github.com/users/treshugart/followers","following_url":"https://api.github.com/users/treshugart/following{/other_user}","gists_url":"https://api.github.com/users/treshugart/gists{/gist_id}","starred_url":"https://api.github.com/users/treshugart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/treshugart/subscriptions","organizations_url":"https://api.github.com/users/treshugart/orgs","repos_url":"https://api.github.com/users/treshugart/repos","events_url":"https://api.github.com/users/treshugart/events{/privacy}","received_events_url":"https://api.github.com/users/treshugart/received_events","type":"User","site_admin":false},"labels":[{"id":228779701,"url":"https://api.github.com/repos/w3c/webcomponents/labels/custom-elements","name":"custom-elements","color":"5319e7","default":false},{"id":841509738,"url":"https://api.github.com/repos/w3c/webcomponents/labels/needs%20concrete%20proposal","name":"needs concrete proposal","color":"1cddc7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":27,"created_at":"2016-09-14T00:27:03Z","updated_at":"2018-03-11T18:04:00Z","closed_at":null,"author_association":"NONE","body":"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:\n\n``` js\nconst Ctor = document.registerElement('x-test', {\n  prototype: Object.create(HTMLElement.prototype)\n});\n\n// x-test\nconsole.log(Ctor.name);\n```\n\nIn Chrome Canary this behaves as I'd expect:\n\n``` js\nclass Ctor extends HTMLElement {}\nwindow.customElements.define('x-test', Ctor);\n\n// Ctor\nconsole.log(Ctor.name);\n```\n\nI 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.\n\nA proposal for this may be to add a method to `CustomElementRegistry` which retrieves the name of the element when passed a constructor:\n\n``` js\n// any getLocalName(Function constructor)\nwindow.customElements.getLocalName(Ctor);\n```\n\nIt could return `null` if not found, or the `localName` if found.\n\nThoughts?\n"},"comment":{"url":"https://api.github.com/repos/w3c/webcomponents/issues/comments/372135404","html_url":"https://github.com/w3c/webcomponents/issues/566#issuecomment-372135404","issue_url":"https://api.github.com/repos/w3c/webcomponents/issues/566","id":372135404,"user":{"login":"thysultan","id":810601,"avatar_url":"https://avatars2.githubusercontent.com/u/810601?v=4","gravatar_id":"","url":"https://api.github.com/users/thysultan","html_url":"https://github.com/thysultan","followers_url":"https://api.github.com/users/thysultan/followers","following_url":"https://api.github.com/users/thysultan/following{/other_user}","gists_url":"https://api.github.com/users/thysultan/gists{/gist_id}","starred_url":"https://api.github.com/users/thysultan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thysultan/subscriptions","organizations_url":"https://api.github.com/users/thysultan/orgs","repos_url":"https://api.github.com/users/thysultan/repos","events_url":"https://api.github.com/users/thysultan/events{/privacy}","received_events_url":"https://api.github.com/users/thysultan/received_events","type":"User","site_admin":false},"created_at":"2018-03-11T18:04:00Z","updated_at":"2018-03-11T18:04:00Z","author_association":"NONE","body":"One use case i'm currently finding for this is as follows.\r\n\r\nWhen i try to call a constructor `new CustomElementCtro` the invocation could either fail because of the registry of an error unrelated to the registry that is rooted in the `constructor` function.\r\n\r\nThe framework has measures in place to handle thrown errors, so i want to avoid swallowing both of these, but it's hard to know where the error is from with the current `TypeError` object since between Chrome, FireFox and Safari only Safari mentions that it is related to the registry(albeit it might just be bad design on my part to try to sniff this info from the TypeError). \r\n\r\nHowever, what i am trying to do is branch only when the error is indeed related to the registry. \r\n\r\nThis allows me to either 1. Display a specific error message or 2. Branch into generating and defining a unique name for the custom element at runtime. I'm sure it's still currently possible to archive this in author space, however the presence of this API would make it a easier to guarantee with either a `has` or `get` variant i.e.\r\n\r\n```js\r\nif (customElements.has(CustomElementCtro))\r\n    branch1\r\nelse\r\n    branch2\r\n```"}}
{"actor":{"display_login":"thysultan"}}