Re: Better event listeners‏

Erik Arvidsson erik.arvidsson at gmail.com
Mon Jan 7 09:27:31 PST 2013


On Mon, Jan 7, 2013 at 12:00 PM, Anne van Kesteren <annevk at annevk.nl> wrote:
> On Mon, Jan 7, 2013 at 5:42 PM, François REMY
> <francois.remy.dev at outlook.com> wrote:
>> However, I've a few issues with your latest proposal:
>
> There's no proposal yet, we're exploring options.
>
> Not quite convinced about yours though as I'm pretty sure we want to
> continue minting lowercase event names and overall it seems way
> complex.

For the Dart DOM we wanted to fix the naming conventions of events as
well as fix some inconsistencies (dblclick is the only one that is
abbreviated for example). I'm not convinced it was worth it. It did
lead to issues where the .type of an event name diverged (or had to be
fixed up internally) from the key in the event map.

One good thing that came out of the Dart experiment was the on
property, which like François mentioned allows IDEs to autocomplete
the known event types. Another neat thing was that the on property was
also defined as a Map<string, EventListenerList> so one could do
indexing for custom events. The known events were simple defined as:

  get mouseOver() {
    return this['mouseover'];
  }

so that the following two were equivalent:

  element.on['mouseover'] === element.on.mouseOver

  element.on['my-custom-event'].add((e) => { console.log(e); })

http://www.dartlang.org/articles/improving-the-dom/#events
http://api.dartlang.org/docs/bleeding_edge/dart_html/Element.html#on
http://api.dartlang.org/docs/bleeding_edge/dart_html/ElementEvents.html
http://api.dartlang.org/docs/bleeding_edge/dart_html/EventListenerList.html

--
erik


More information about the es-discuss mailing list