PDA

View Full Version : [CLOSED]Ext.util.Event and fire bug?



gevik
16 Feb 2011, 5:52 PM
The fire method in Ext.util.Event adds an additional object to the event arguments. Is this intended or a bug?

Example:


new Ext.Button({
text:'Hello World',
renderTo:Ext.getBody(),
listeners:{
click:function(){
console.log(arguments);
}
}
});


In Ext3 you get 2 arguments:


[Object { initialConfig={...}, text="Hello World", more...}, Object { browserEvent=, button=0, more...}]


In Ext4 you get 3 arguments:


[Object { initialConfig={...}, text="Hello World", more...}, Object { browserEvent=, type="click", more...}, Object {}]


This is caused by ext-core-debug.js:12813:fire:


if (listener.o) {
args.push(listener.o);
}

TommyMaintz
17 Feb 2011, 3:16 AM
This is useful for passing on any data to the listeners. By adding it to the options object when you set up the listener, you can access them easily. Also it allows you to do specific behavior in your listeners based on the options you used to set them up (like buffer, delay etc).

gevik
17 Feb 2011, 3:41 AM
I see the benefit of passing the listener object to the handler function inside the same listener. Since the listener.o is added by default means that EVERY fireEvent call in the framework will have this extra argument. Unless this is carefully re-factored in the framework it will case hard to find bugs when using/slicing the javascript arguments variable.

I noticed this because I have implemented a custom Ext.Direct provider for our Ext4Yii framework. The provider broke since the listener.o was not expected as an arguments item.

I fixed it using array.pop() in our provider.