PDA

View Full Version : [B3] Observable mixin broken?



egorfine
23 Feb 2012, 6:26 AM
Ext.define('common.Connection', {
singleton: true,

mixins: {
observable: 'Ext.util.Observable'
},

socket: null,

constructor: function() {
this.addEvents(['offline','connecting', 'online']);

Ext.onReady(Ext.bind(function() {
this.fireEvent('connecting');


this.socket = io.connect(null);
this.socket.on('error', Ext.bind(this.onError, this));
}, this));
},


onError: function(reason) {
this.fireEvent('offline', reason);
}
});


This code worked perfectly in ExtJS 4.0.7, 4.1b1 and 4.1b2, but fails on ExtJS 4.1b3 in Observable.js line 444.

Adding "hasListeners: {}" into class fixes it and everything seems working.

A bug?

skirtle
23 Feb 2012, 6:34 AM
I don't think this is a bug. Try calling the mixin constructor after you call addEvents:


this.mixins.observable.constructor.call(this);

dongryphon
26 Feb 2012, 2:42 PM
@skirtle is correct - not calling the Observable constructor was previously harmless, though bad form (one should always call a constructor).

In 4.1b3 we've added optimizations to Observable that allow us to avoid lots of unnecessary function calls when firing events for which no one is listening. This is initialized in the Observable constructor.

This optimization caused problems with the EventBus used by MVC applications (which is now fixed in the nightly builds).

egorfine
9 Mar 2012, 4:54 AM
Thanks!

dongryphon
9 Mar 2012, 11:05 AM
Thanks!

Thank you for digging in and reporting the problem. :)