[dojo-contributors] Event handling proposal

Kris Zyp kzyp at dojotoolkit.org
Wed Mar 16 18:33:17 EDT 2011

On 3/16/2011 11:35 AM, Eugene Lazutkin wrote:
> Inline.
> On 03/15/2011 04:29 PM, Kris Zyp wrote:
> > Looking at how to add has() branching for dojo/_base/event.js and
> > considering other improvements that I have wanted to see in our event
> > handling, I put together a rework of the event system I wanted to
> > propose to you. This is based on work from Bryan, ideas from Eugene,
> > current discussions on dojo.touch, has, and more. This diff is here:
> > http://bugs.dojotoolkit.org/attachment/ticket/12451/events.diff
> It doesn't work for me --- shows blank. I'll retrieve it and go over
> locally, when I have time.
Any idea how to fix that?
> > It is not quite complete, but most of functionality is
> > in there. This is intended to be fully backwards compatible. Here are
> > the main improvements/ideas:
> > * Uses has() branching
> +0.
> > * Function event types, allowing you to create new custom/extension
> > events (like dojo/touch.press) in a safe extensible way. Special
> > handling of certain key events (keypress, onmouseleave, and onmousenter)
> > are implemented using extension events. For example:
> > dojo.connect(node, dojo.touch.press, listener);
> Sounds interesting. It would be nice to see 2-3 real world examples of
> that. If it works properly, it could be a fantastic way to define
> app-specific and/or generic/synthetic events.

I am not sure if by "real world" you mean outside of Dojo, but one of
the first and foremost applications I hoping for is that we can have all
our touch and gesture events be extension events.
define(["dojo/listen", "dojo/gesture"], function(listen, gesture){
  listen(node, gesture.swipe, callback);
Note that the way it is written, you can easily use extension event
functions directly as well:
gesture.swipe(node, callback);

Also, I already moved keypress, onmouseenter, onmouseleave out of core
event listening code and made them extension events. They can be used
directly like (dojo.connect does this automagically):
define(["dojo/listen", "dojo/mouse"], function(listen, mouse){
  listen(node, mouse.enter, callback);

> [snip]
> > * list provides separation of events and methods. You can have a "start"
> > method that conditionally triggers a "start" event (mapped to
> > "onstart"), for example.
> I started to do something like that in Pulsar and on a surface it looks
> like a good idea. Again, the devil is in details, in this case in the
> implementation.

Yeah, definitely open to your ideas here. I have been wondering if the
handle returned from connect/listen should have a then() method (but
would it fire multiple times, or just once?).

More information about the dojo-contributors mailing list