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

RE: Callback when an event handler has been added to a custom element

From: Domenic Denicola <d@domenic.me>
Date: Sat, 7 Nov 2015 09:11:43 +0000
To: Mitar <mmitar@gmail.com>
CC: public-webapps <public-webapps@w3.org>
Message-ID: <CY1PR0501MB13698E9A124DE8D7FC07D1B6DF170@CY1PR0501MB1369.namprd05.prod.outlook.com>
From: Mitar [mailto:mmitar@gmail.com] 

> Hm, but message port API itself has such a side-effect:

I think that is just a very bad API. The platform is unfortunately full of bad APIs :). In particular, a difference between two different ways of adding event listeners is not something authors ever think about.

But regardless, if that's all you want, you could do it easily by declaring your custom element class like so:

class MyCustomElement {
  set onmessage(handler) {
    this.addEventListener("message", handler);
    this.start();
  }
  // ...
}

> For me this feels like leaking internal implementation details to the outside.

I strongly disagree. I would instead say it feels like getting rid of magical implicit I/O behavior, in favor of making the code say what it does and do what it says.

Received on Saturday, 7 November 2015 09:12:13 UTC

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