I have found that when creating an advanced prototype based
class/widget, that all of the Event.observe and Event.stopObserving
handling gets to be a pain in the ass..

I think it would be great to extend the current Event methods in
Prototype to support some sort of "grouping" of events. Depending on
the options, some do not always need to be removed so dispose functions
typically look like:
Event.stopObserving(...,...,...);
Event.stopObserving(...,...,...);
Event.stopObserving(...,...,...);
if(this.blah) Event.stopObserving(...,...,...);
if(this.blah) Event.stopObserving(...,...,...);


I think a better scheme *in these cases* would be something like this
when adding observers:
Event.addObserver(key, element, name, observer, useCapture);
and then, the dispose function would simply call something like
Event.stopObservers(key);

I'm thinking "this" would be a good key in most such cases. Does anyone
see a problem with that?
An added benefit here is that when extending classes that use this
scheme, the programmer wouldn't have to worry about stopping his own
observers as long as he used the same key. IPE comes to mind, all of
the times I have extended createElement() functionality, adding
observers and not having a good way to make sure they are disposed of
later on unless I also extend IPE's own dispose().

This would also allow you to not have to store references to the event
handler functions if you know you won't be manually removing it later:
Event.addObserver(this,element,'click',this.clickElement.bindAsEventListener(this));
The handler function would be stored in the observers cache, and it
could be unloaded as part of the stopObservers call.

I'm just brainstorming at this point and will probably try to cook up
some code and submit a patch, but I'd like to get some feedback. I
think this would be a huge benefit to programmers like me who are
making pages that have a potentially high amount of dynamic adding and
removing going on.

Thanks,
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