Re: Better event listeners‏

On Mon, Jan 7, 2013 at 12:00 PM, Anne van Kesteren <annevk@annevk.nl> wrote:
> On Mon, Jan 7, 2013 at 5:42 PM, François REMY
> <francois.remy.dev@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

Received on Monday, 7 January 2013 17:28:18 UTC