W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2014

Re: [Custom]: Rename "createdCallback" to "created"

From: Jarek Foksa <jarek@foksa.name>
Date: Mon, 6 Oct 2014 19:21:52 +0200
Cc: Matthew Robb <matthewwrobb@gmail.com>, "Takayoshi Kochi (河内 隆仁)" <kochi@google.com>, public-webapps <public-webapps@w3.org>
Message-Id: <5417FEA5-AEFA-4AD9-B61D-784F0702C3C6@foksa.name>
To: "James M. Greene" <james.m.greene@gmail.com>
> On 2014-10-06, at 18:24, James M. Greene <james.m.greene@gmail.com> wrote:
> This only thing about this approach that is slightly inconsistent with the rest of the Web Platform is assuming that the `this` context within the handler will be set to the element, rather than being forced to grab it via `event.target`.

ES6 arrow functions are going to solve the problems with “this” scoping inside event handlers.

Ideally I would prefer to have a constructor instead of createdCallback(), and “attach”, “detach” and “attributechange” events instead of the other lifecycle callbacks. The constructor idea was already discussed here for a long time [1], but if I understand correctly it wasn’t approved due to performance issues.

> let Button = document.registerElement(“x-button”, class Button extends HTMLElement {
>   constructor() {
>     this.addEventListener(“attach”, () => this.attached() );
>     this.addEventListener(“detach”, () => this.detached() );
>     this.addEventListener(“attributeChange”, () => this.attributeChanged() );
>   }
>   attach() {
>     console.log(“Attached host element”);
>   }
>   ...
> }

[1] http://lists.w3.org/Archives/Public/public-webapps/2013OctDec/0793.html
Received on Monday, 6 October 2014 17:22:18 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:31 UTC