[dojo-contributors] Event handling proposal

Bill Keese bill at dojotoolkit.org
Wed Mar 16 21:45:15 EDT 2011

>   * 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)
>>   You mean like http://bugs.dojotoolkit.org/ticket/9692 ?
>  Are you saying that widgets could emit custom events (ex: onWidgetClick)
>  that bubble up the DOM tree?   Apps could (for example) listen for those
> events on dojo.body()?
>   I hadn't intended to get that far with it, I was just going to do plain
> method calls (and as an base class, it can only be a base class for JS
> objects, not DOM objects). The intent was more to align with Node style
> EventEmitter. The DOM triggering sounds cool though.

Oh I see.    Like http://twoism.posterous.com/emitting-events-with-nodejs ?
  Yes, agreed, I want widgets to have an on() method for users to connect to
widget events.

>   Pete, you were working on that but got stuck and couldn't finish.   What
> was the issue you had?
>>  * list provides separation of events and methods. You can have a "start"
>> method that conditionally triggers a "start" event (mapped to
>> "onstart"), for example.
>  Didn't follow this.
> Sorry, this was kind of a vague reference to earlier discussions on
> separating methods and events.
> More specifically, dojo/listen would follow the DOM paradigm of an event
> name being prefixed with "on" to get the slot name.
> define(["dojo/listen", function(listen){
>     var obj = {};
>     listen(obj, "foo", function(){ alert("foo event")});
>     obj.onfoo(); -> alert "foo event"
>     obj.foo = function(){ alert("foo method");};
>     obj.foo(); -> alert "foo method"
> });
> dojo.connect would still retain it's current behavior of using the same
> namespace for method and event.

OK, not sure why you need/want a method called "onfoo" at all though?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-contributors/attachments/20110317/2287c2bf/attachment.htm 

More information about the dojo-contributors mailing list