ExtJs currently does not support removal of controllers out of the box. To cleanup a controller, do the following:
- Extend
Ext.app.EventBus
with a methoduncontrol
that unregisters all event listeners that this controller registered on the EventBus. Check out the source ofExt.app.EventBus#control
to derive an implementation. Or use this one. - Extend
Ext.app.Application
with a methodremoveController
that removes a given controller instance from thecontrollers
collection. It's a Ext.util.MixedCollection, check out the source forExt.app.Application#getController
. Then clean up all registered listeners for that controller usinguncontrol
. - Implement a
destroy
method either on your specific controller and/or extendExt.app.Controller
. You should at least callclearManagedListeners()
and possibly destroy other objects created by this controller like views or stores, if that suits your application architecture and controller life-cycle.
source:
Ext.override(Ext.app.EventBus,{
uncontrol:function(controllerArray){
var me=this,
bus=me.bus,
deleteThis,idx;
Ext.iterate(bus,function(ev,controllers){
Ext.iterate(controllers,function(query,controller){
deleteThis=false;
Ext.iterate(controller,function(controlName){
idx=controllerArray.indexOf(controlName);
if(idx>=0){
deleteThis=true;
}
})
if(deleteThis){
delete controllers[query];
}
})
})
}
})
Ext.override(Ext.app.Application,{
removeController:function(controllerArray){
var me = this;
me.eventbus.uncontrol(controllerArray);
}
})
Ext.override(Ext.app.Controller,{
destroy:function(){
var me=this;
this.clearManagedListeners();
}
})