Results 1 to 4 of 4

Thread: How to unload an MVC controller?

  1. #1
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,887
    Answers
    18
    Vote Rating
    541
      0  

    Default Unanswered: How to unload an MVC controller?

    My application dynamically creates and destroys views. I can dynamically load an MVC controller, but how do I unload it when the view is destroyed and the controller is no longer needed?

  2. #2
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    3,015
    Answers
    33
    Vote Rating
    182
      0  

    Default

    Is there a need to clean it up? Controller doesn't implement any destroy method since it doesn't really allocate any resources or create any DOM elements. If it registers listeners on the view, those will be cleaned up when the view is destroyed. So it should only be a simple Object in memory, I doubt there will be much to gain by trying to 'unload' it. I guess you could do:

    Code:
    this.control({ 'viewselector' : { destroy : function() { MyApp.MyController = null; } });

  3. #3
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,887
    Answers
    18
    Vote Rating
    541
      0  

    Default

    The controller might still be responding to application events when the view is destroyed. There's just no need for the controller to do anything since there's no view to control. So, I think, there should be an option to suspend the controller until the view is re-created. Another option is to destroy the controller and remove it from the list of controllers so no events are dispatched to it.

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,326
    Answers
    3884
    Vote Rating
    1297
      1  

    Default

    You can uncontrol the control I have a SubAppDemo proof of concept that automatically adds and removes controllers. I add an uncontrol method to the Ext.app.EventBus (works in 4.0.6, haven't updated):

    https://github.com/mitchellsimoens/S...pp.EventBus.js

    You just pass an array of controller ids to the uncontrol method:

    Code:
    bus.uncontrol([controller.id]);
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •