PDA

View Full Version : Controllers & Events



Bleak
25 Mar 2014, 5:21 AM
I have a controller (LinkManager), that manages a grid containing links. When a user clicks on a link, the LinkManager passes control to another controller called LinkEditorMgr. The LinkEditor fires events, such as record saved so I have events listening on the LinkEditor as follows allowing it to refresh the grid for the view in LinkManager;




/**
* Add a new link into the system
*/
addLink : function() {
var linkController = this.getController('linkmanager.LinkEditorMgr');
// If the controller issues a save event, reload the link manager grid
// to keep it in sync;
this.mon(linkController, 'link.recorded.saved', this.prepare, this);
// just pass through
linkController.addLink();
}


The issue is simply that since Controllers are never destroyed, this event is never unregistered. I can have multiple instances of the LinkEditorMgr running since the user can be editing multiple links at the same time.


The problem I have, is that the linkController is still trying to handle events even if I chose to close view associated to the LinkManager and obviously its grid reference is no longer valid.


How do I unregister the events?


Thanks

israelroldan
2 Apr 2014, 9:59 AM
What's the scope of that addLink function (value of this)? You'd need to make sure it is something that actually gets destroyed so the Managed listener can be removed as well. At this moment, controllers never get destroyed (that will change on Ext 5 with the introduction of ViewControllers).

Bleak
2 Apr 2014, 10:10 AM
The introduction of ViewControllers will be amazing, as I have a single controller managing 1-many instances of a specific View. I've managed to work around the event management a bit, but knowing I could destroy a Controller with a View would be incredible.

israelroldan
2 Apr 2014, 10:54 AM
Yeah, that's one of the main features of Ext 5.0. Stay tuned for the public beta! :D