Better event listeners

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Jan 7 11:19:14 PST 2013


I like the naming convention, I don't like node.js in the picture because
of double argument with that error as first one each time rather than an
e.type === "Error"

I also would like to show another example of handleEvent and remitEvent
proposal I have described a while ago:

/**
 *  interface ObjectHandler implements EventListener {
 *      void                handleEvent(in Event evt);
 *      void                remitEvent(in Event evt);
 *      attribute   Object  events;
 *  };
 *
 *  @link   http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventListener
 */var ObjectHandler = {
  handleEvent: function handleEvent(e) {
    var
      events = this.events,
      type = e.type
    ;
    if (events.hasOwnProperty(type)) {
      events[type].call(this, e);
    }
  },
  // it could be called removeEvent too, as you wish  remitEvent:
function cancelEvent(e) {
    e.currentTarget.removeEventListener(
      e.type, this, e.eventPhase === e.CAPTURING_PHASE
    );
  }
};


(http://webreflection.blogspot.de/2012/01/introducing-objecthandler.html)




On Mon, Jan 7, 2013 at 11:15 AM, Rick Waldron <waldron.rick at gmail.com>wrote:

> I wonder if this is the moment where redemption can happen... Instead of
> trying to invent some kind of new approach, why not standardize on the
> massive, 16 lane, mega-highway cow-path just waiting to be paved:
>
> on => addEventListener
> off => removeEventListener
> emit => dispatchEvent
>
>
> I'd suggest Node's EventEmitter (and EventEmitter2) as a reasonable
> starting point for an ideal, "subclassable" EventTarget-like system.
>
>
> Rick
>
>
> On Mon, Jan 7, 2013 at 12:32 PM, François REMY <
> francois.remy.dev at outlook.com> wrote:
>
>> ----------------------------------------
>> > Date: Mon, 7 Jan 2013 18:00:59 +0100
>> > From: annevk at annevk.nl
>> > To: francois.remy.dev at outlook.com
>> > CC: www-dom at w3.org; es-discuss at mozilla.org
>> > Subject: Re: Better event listeners
>> >
>> > 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.
>>
>> No problem with that, we're here to discuss. As you note, this is still
>> early exploration ;-) My concerns continue to hold, however.
>>
>> If we can a solution that works well with autocompletio, where you can
>> test the existence of an event before registering to it (in a way that
>> enables polyfills) and that doesn't remove abilities from the current
>> syntax, I'll be all right. If we don't match those criteria, however, I'm
>> not sure this approach is worth pursuing.
>>
>> To respond to Benoit's answer, I do think 'onclick' was a good approach
>> that just missed the '+=' and '-=' operators of C#. Maybe adding support
>> for them would be an alternative approach? Don't know how practical it's
>> from an ECMAScript point of view, however. Proxying 'null' to support just
>> '+' and '-' operators on it would be awsomely insane ^_^
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130107/3123ce26/attachment.html>


More information about the es-discuss mailing list