PDA

View Full Version : Ext.util.Observable.hasEvent and removeEvent



Condor
6 Jul 2009, 6:23 AM
I'm using an Ext.util.Observable as a generic message bus.

For this it would be useful if Ext.util.Observable would have a hasEvent and a removeEvent method.


Ext.override(Ext.util.Observable, {
hasEvent: function(eventName){
var evt = this.events[eventName];
return Ext.isObject(evt) || (evt === true);
},
removeListeners: function(eventName){
var evt = this.events[eventName];
if(Ext.isObject(evt)){
evt.clearListeners();
}
},
removeEvent: function(eventName){
this.removeListeners(eventName);
delete this.events[eventName];
}
});

evant
6 Jul 2009, 6:27 AM
To clarify, the intent here is to:

a) Check if the object has any listeners of a particular name
b) Remove all events of a particular name

Condor
6 Jul 2009, 6:32 AM
No, not really.

a) hasEvent should check if the event (with or without listeners) is defined (hasListener already checks for registered listeners).
b) removeEvent should remove not only the listeners, but the entire event. What you describe would match a removeListeners(eventName) method (added to the code above for clarity).

hendricd
6 Jul 2009, 6:33 AM
@Condor -- I like where you're headed with that, and I thought about adding similar features to this silly variant. (http://extjs.com/forum/showthread.php?p=203156#post203156)

Really could use hasEvent(event), hasSubscribers(event), too.