Opened 11 years ago

Last modified 9 years ago

#12451 closed enhancement

Event handling improvements — at Initial Version

Reported by: Kris Zyp Owned by: Kris Zyp
Priority: high Milestone: 1.7
Component: Events Version: 1.6.0
Keywords: Cc: Eugene Lazutkin, [email protected]…, ben hockey, dante, Rawld Gill
Blocked By: Blocking:


This is proposal for some rework of event handling. Here are the main improvements/ideas:

  • Uses has() branching
  • Function event types, allowing you to create new custom/extension

events (like dojo/ 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,, listener);

  • Introduce a new lightweight dojo/listen module/function that can be

used sans the large blocks of corrective code for keypress, onmouseleave, and onmousenter emulation (particular useful to avoid for mobile apps).

  • Modularization - Trying to improve the modularity of our event handling:

There is several distinct pieces of functionality in dojo/_base/event.js that is broken out:

  • keypress handling - this is moved out to dojo/_base/keypress.js as a

custom extension/emulation event.

  • mouseenter/mouseleave handling - moved to dojo/mouse.js as a custom

extension/emulation event.

  • aop - Used for listening to regular object's methods, can be used on

its own, but leveraged by listen module (dojo/aop)

  • listen - The main listening component, this does not do include

special code for specific events, but it does include the IE event normalization code.

  • connect - Back-compatible delegation to the other modules, if you look

in connect.js you will see how it does the magical mapping of named events to these custom events Note that some of these ideas for aop/listening have been suggesting for 2.0. However, this patch adds this functionality without breaking compatibility, so it seems like it might be viable in 1.x.

  • NodeList?.prototype.on() maps to listen() function -

dojo.query(".class").on("some-event", callback);

  • Return value from connect() and listen()/on() is an object with three

methods: cancel(), pause(), and resume() dojo.disconnect(handle) still works, but can do handle.cancel() instead (as well as pause and resume)

  • dojo/listen provides an Evented base class that can be extended for

event emitting objects, providing on() and emit() methods (could be used by a future widget class hierarchy)

  • list provides separation of events and methods. You can have a "start"

method that conditionally triggers a "start" event (mapped to "onstart"), for example.

Change History (0)

Note: See TracTickets for help on using tickets.