Changes between Version 1 and Version 2 of Ticket #12451


Ignore:
Timestamp:
Mar 16, 2011, 5:41:44 PM (9 years ago)
Author:
Eugene Lazutkin
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #12451

    • Property Cc Eugene Lazutkin added
  • Ticket #12451 – Description

    v1 v2  
    11This is a proposal for some rework of event handling. Here are the main improvements/ideas:
    22
    3  * Uses has() branching
    4  * 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
    5     {{{dojo.connect(node, dojo.touch.press, listener);}}}
    6  * 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).
    7  * 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:
    8     - keypress handling - this is moved out to dojo/_base/keypress.js as a custom extension/emulation event.
    9     - mouseenter/mouseleave handling - moved to dojo/mouse.js as a custom extension/emulation event.
    10     - aop - Used for listening to regular object's methods, can be used on its own, but leveraged by listen module (dojo/aop)
     3 * Uses `has()` branching
     4 * 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:
     5{{{
     6#!js
     7dojo.connect(node, dojo.touch.press, listener);
     8}}}
     9 * 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).
     10 * 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:
     11    - `keypress` handling - this is moved out to `dojo/_base/keypress.js` as a custom extension/emulation event.
     12    - `mouseenter`/`mouseleave` handling - moved to `dojo/mouse.js` as a custom extension/emulation event.
     13    - aop - Used for listening to regular object's methods, can be used on its own, but leveraged by listen module (`dojo/aop`)
    1114    - listen - The main listening component, this does not do include special code for specific events, but it does include the IE event normalization code.
    12     - 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
     15    - 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
    1316
    1417    Note that some of these ideas for aop/listening have been suggested for 2.0. However, this patch adds this functionality without breaking compatibility, so it seems like it might be viable in 1.x.
    15  * NodeList.prototype.on() maps to listen() function -
    16     {{{dojo.query(".class").on("some-event", callback);}}}
    17  * 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)
    18  * 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)
     18 * `NodeList.prototype.on()` maps to `listen()` function -
     19{{{
     20#!js
     21dojo.query(".class").on("some-event", callback);
     22}}}
     23 * 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)
     24 * `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)
    1925 * listen provides separation of events and methods. You can have a "start" method that conditionally triggers a "start" event (mapped to "onstart"), for example.