Consider the following example class Parent:
Ext.define('Parent', {
...
listeners: {
render: {
fn: doSomething
},
},
};
and the following class Child extending default Parent above:
Ext.define('Child', {
extend: 'Parent',
...
listeners: {
afterrender: {
fn: doSomething
},
},
};
Even though Child does not specify a listener for render (it only provides for afterrender) the render listener (defined in the Parent class) is not fired anymore upon Child‘s component rendering; i.e. the listener is overwritten by the new listeners specification.
How to fix this?
You can specify the handler in
initComponent, instead of using thelistenersconfig object.The reason that the
listenersconfig method doesn’t work is because the config object that is passed toExt.definegetsExt.apply‘d to any new objects that are created. In other words, it completely overwrites any reference types (e.g. thelistenersobject).Using
initComponentis preferred, since it’s specifically designed to be overridden for subclassing.