1. #1
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,408
    Vote Rating
    179
    Answers
    13
    LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold

      0  

    Default Unanswered: How to unload an MVC controller?

    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
    2,782
    Vote Rating
    112
    Answers
    33
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      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
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,408
    Vote Rating
    179
    Answers
    13
    LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold LesJ is a splendid one to behold

      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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,548
    Vote Rating
    872
    Answers
    3566
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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.

Thread Participants: 2