View Full Version : When did Ext.util.Observable.addEvents() become obsolete?

23 Aug 2012, 5:59 AM
I have come to the conclusion that addEvents is useless :)

So - supposedly - addEvents "adds the specified events to the list of events which this Observable may fire."

addEvents: function(o) {
if (typeof o == 'string') {
for (args = arguments, i = args.length; i--; ) {
arg = args[i];
if (!events[arg]) {
events[arg] = true;

but then in addListener, there's this chunk of code :)

ename = ename.toLowerCase();
me.events[ename] = me.events[ename] || true; <- what's this doing here? ^^
event = me.events[ename] || true; <- also this ?!
if (Ext.isBoolean(event)) {
me.events[ename] = event = new Ext.util.Event(me, ename);

Thus, there is no "allowed list" of events the Observable may fire.
You can simply add the listeners and then fire the events, without ever needing to call addEvents.

For example, here: http://ext4all.com/post/mvc-application-add-custom-events - if you copy the code, comment the line this.application.addEvents('UsersStoreLoaded'); - the code will run just fine and the events will be triggered as expected.

So what's the purpose of addEvents() ? Backwards compatibility?

23 Aug 2012, 10:32 AM
See this ticket (http://www.sencha.com/forum/showthread.php?198969-Observable-deprecate-addEvents)

S (http://www.sencha.com/forum/showthread.php?198969-Observable-deprecate-addEvents)ome Ext 4.1.1 classes don't even use addEvents anymore, see for instance data.Store

(http://docs.sencha.com/ext-js/4-1/source/Store.html#Ext-data-Store)It lists events for documentation purpose, but it doesn't call addEvents.

23 Aug 2012, 12:28 PM
Heh, I thought so too.

You can always use it to reset the listeners on a particular event without calling removeListener() :)