> >  I guess my point is: Keep the normal Event class simple and add extra
> > functionality in another layer.Very good point, Tobias. I like what you're 
> > suggesting.

Thanks for the input, I've rewritten it with what, and I think you'll 
agree, is a much better API.
New ticket: http://dev.rubyonrails.org/ticket/7435
I'll close the old one as soon as the Trac system starts responding 
again...

This one uses an EventCache class to attain the grouping feature:
this.events = new EventCache();
It makes Event work just like any other instance of EventCache, so the 
observe and stopObserving methods are now actually part of the 
EventCache class, making the API both backwards compatible and 
extremely familiar:
this.events.observe(element,'click',function(){}); // or the original 
way:
Event.observe(element,'click',function(){});

I've also added the "wildcard" feature to stopObserving so you can do 
any of the following in addition to the original API:
this.events.stopObserving(); //clears all observers in this particular 
cache
Event.stopObserving(element); //clears all observers in the main cache 
on this element
Event.stopObserving(element,'click'); //clears all 'click' observers 
on this element in this cache

I think the cache separation is a major bonus to the new wildcard 
feature as well.  Without it, the wildcards could be VERY dangerous. 
Imagine you have a tooltip class that is applied to a group of 
elements and there is also say a hover effect applied to the same 
group of elements via a different widget that has no knowledge of the 
tooltip widgets.  Removing listeners on one with a wildcard could 
easily kill your other listeners *unintentionally* by calling:
Event.stopObserving(this.element);
but with the cache separation you could safely:
this.events.stopObserving();
without touching the other observers created by a different widget on 
the same element!
Never has event handling been so easy and clean to my knowledge. I 
looked at Mootools, jQuery, etc.. and none of them do anything to 
protect against this kind of problem, which I can see happening *very* 
easily.

Colin


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to