PDA

View Full Version : Ext.AbstractManager.onAvailable registered listeners never fire



superstructor
28 Jun 2011, 1:06 AM
Sencha Touch version tested:

1.1.0

only default ext-all.css




Platform tested against:

iOS 4.3
iOS 5
Chome 14 (for development)


Description:

Listeners registered on subclasses of AbstractManager e.g. ControllerManager for when a component becomes available never fire due to an incorrect event signature in the implementation of onAvailable.


Test Case:



Ext.regController('Foo', {
init: function() {
console.log('Foo init');
Ext.ControllerManager.onAvailable('Bar', function() {
console.log('Bar is available');
});
}
});

Ext.regController('Bar', {
init: function() {
console.log('Bar init');
}
});




Steps to reproduce the problem:

register a listener with onAvailable on a subclass on AbstractManager
listener never fires


The result that was expected:

listener fires when component with matching id is available


The result that occurs instead:

listener never fires


Debugging already done:

yes


Possible fix:

The signature of the listener on the this.all collection that implements the onAvailable listener is wrong.

Current as of 1.1.0


onAvailable : function(id, fn, scope){
var all = this.all;

all.on("add", function(index, o){
if (o.id == id) {
fn.call(scope || o, o);
all.un("add", fn, scope);
}
});
},


Correct


onAvailable : function(id, fn, scope){
var all = this.all;

all.on("add", function(hashmap, key, o){
if (key == id) { // or if o.id == id would work now too
fn.call(scope || o, o);
all.un("add", fn, scope);
}
});
},


Even better the following would fix a second bug where the listener won't fire if the component has already been registered. This can be important when using asynchronous script loading.


onAvailable : function(id, fn, scope){
var all = this.all,
item = all.get(id);

if (item) {
fn.call(scope || item, item);
} else {
all.on("add", function(hashmap, key, o){
if (key == id) { // or if o.id == id would work now too
fn.call(scope || o, o);
all.un("add", fn, scope);
}
});
}
},



Sencha touch is an impressive framework with a lot of potential. In my opinion its currently the best available mobile JS framework.

Unfortunately there are so many bugs, architectural issues and incorrect documentation that I don't have enough time to write up bug reports for each one.

So heres a start... please fix it.