{"action":"closed","issue":{"url":"https://api.github.com/repos/w3c/webcomponents/issues/546","repository_url":"https://api.github.com/repos/w3c/webcomponents","labels_url":"https://api.github.com/repos/w3c/webcomponents/issues/546/labels{/name}","comments_url":"https://api.github.com/repos/w3c/webcomponents/issues/546/comments","events_url":"https://api.github.com/repos/w3c/webcomponents/issues/546/events","html_url":"https://github.com/w3c/webcomponents/issues/546","id":170988659,"number":546,"title":"Custom event handlers support","user":{"login":"chris-morgan","id":392868,"avatar_url":"https://avatars1.githubusercontent.com/u/392868?v=4","gravatar_id":"","url":"https://api.github.com/users/chris-morgan","html_url":"https://github.com/chris-morgan","followers_url":"https://api.github.com/users/chris-morgan/followers","following_url":"https://api.github.com/users/chris-morgan/following{/other_user}","gists_url":"https://api.github.com/users/chris-morgan/gists{/gist_id}","starred_url":"https://api.github.com/users/chris-morgan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chris-morgan/subscriptions","organizations_url":"https://api.github.com/users/chris-morgan/orgs","repos_url":"https://api.github.com/users/chris-morgan/repos","events_url":"https://api.github.com/users/chris-morgan/events{/privacy}","received_events_url":"https://api.github.com/users/chris-morgan/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}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-08-13T02:31:03Z","updated_at":"2018-03-05T04:27:22Z","closed_at":"2018-03-05T04:27:22Z","author_association":"NONE","body":"`<img onerror>`, `<button onclick>`, _&c._: these things are convenient and consistent. But custom events? One can create and dispatch custom events easily, but you don’t get the `onfoo` attribute and property for free, and it’s not so easy to get them working with the same semantics as the built-in event types.\n\nI believe that Custom Elements is a great place to canonise the pattern and provide a standard implementation of this bit of scaffolding for custom events, so that they just work as expected, just like Custom Elements is all about making such things just work as expected from HTML authors. I expect that doing this will encourage the use of custom events as well (where people simply haven’t thought about it, for example, but they see that it’s now easy to do), which I think is probably a good thing.\n\nDefining an event attribute `foo` has two parts; the property `onfoo` is added to the element’s prototype, and its HTML attribute `onfoo` is monitored and the `onfoo` property updated when the attribute changes.\n\nI see two main approaches to specifying this (that an element of type `MyFancyElement` can have a `foo` event dispatched on it and thus should provide and support the `onfoo` attribute and property):\n1. A property like `observedAttributes`, producing a sequence of event names (`['foo']`). `customElements.define` would then add the properties to the class prototype at that point (this is feeling like metaclasses) and set whatever monitoring for the HTML attributes is required in place.\n2. Make an extra function call (`customElements.defineEventAttributes(MyFancyElement, ['foo'])` or similar) which adds the properties to the class prototype and sets things up, rather than making `customElements.define` do it.\n\n(If we wait for standardisation of ES7 decorator proposal they could make the latter approach neater. Aside, I’d like `customElements.define` to support being called as a decorator.)\n\nThis proposal is easily polyfilled; https://github.com/chris-morgan/custom-element-events is such a polyfill (using the second approach, so it can sit on top of a native implementation or a polyfill).\n\n---\n\nThere’s also the possibility of making this more general, using the second approach but making it work with _any_ element by putting the property on `HTMLElement.prototype` or similar. This would make custom events work as expected for _any_ element, and is not a bad idea. This would take it out of the scope of Custom Elements specification, though, and I’m not sure where it’d wind up, though still as a part of the web apps working group, I imagine. Maybe it’d be a new specification. I dunno. Anyway, I wouldn’t object to it being implemented generally like that. I believe it should also be straightforward to polyfill, I believe.\n"}}
{"actor":{"display_login":"annevk"}}