View Full Version : Applying multiple listeners to a config

5 Oct 2013, 2:44 AM

Assume you are creating an xtype config (not working with an instantiated component!), but the configuration is broken up a little so you may have to invoke the help of the same listener two times in different places.

Does Ext.apply help so as to not have the one listener config overwrite the other?

Any ideas on how to get around this if it does not?

6 Oct 2013, 10:18 PM
You can call Ext.merge.

6 Oct 2013, 11:42 PM
I will take that as bad advice

Here is what I did.

I made a method called extendConfigListeners

and it does this...

function (xtype, name, newFn) {

var listener,

if ( xtype.listeners && xtype.listeners[name] ) {

listener = xtype.listeners[name];

// Listener is object made
if ( listener.fn && Ext.isFunction(listener.fn) ) {
oldFn = listener.fn;

// Listener is shorthand made
else if ( Ext.isFunction(listener) ) {
oldFn = listener;

if ( oldFn )
delete xtype.listeners[name];

if ( !xtype.listeners )
xtype.listeners = {};

xtype.listeners[name] = {
fn: function() {

if ( oldFn ) {
oldFn.apply(this, arguments);
if ( newFn ) {
newFn.apply(this, arguments);

return xtype;

7 Oct 2013, 6:29 AM
Also it seems to me there is no Ext method to prevent an overwrite of a new config listener.

Would make sense to me if an apply method that could take care of this would be made!

I will hit the answer button on my own answer, if that is wrong - someone must tell me!

The answer above is way wrong IMO, and you should not follow that!