1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    13
    Vote Rating
    0
    tyfab is on a distinguished road

      0  

    Default Unanswered: Dynamic controllers loading

    Unanswered: Dynamic controllers loading


    Hi,

    I have a question regarding the way designer 2 handle MVC.

    I have design several views with a controller for each :
    let say :
    mainview (just an empty viewport) -> maincontroller
    secondview (empty tab form) -> another controller
    third view (first tab) -> third controller
    ...

    When i execute, i can see that everything that is link, is loaded (all the controllers, views, store, models,...)
    In my application "controllers section" , i can see all the conttollers, but i would like to have just one "maincontroller" loaded first and then call the others when needed and if needed,

    Reading the forum, I have see some solution, but none that can be handle directly from designer 2

    any suggestion ?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Answers
    3500
    Vote Rating
    854
    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

      0  

    Default


    Ext JS 4 MVC should have all controllers loaded upfront.
    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.

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    13
    Vote Rating
    0
    tyfab is on a distinguished road

      0  

    Default then ...

    then ...


    Sorry but the term up front doesn't means anything to me (french)

    Then you mean that there is no way to add controller dynamicaly ... in case of large application for example ..or depending on certain variable ?

    fabrice

  4. #4
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    101
    Answers
    8
    Vote Rating
    3
    sskow200 is on a distinguished road

      0  

    Default


    This is not a desirable aspect of what the controllers are supposed to do. In this MVC architecture the controllers do event handling for your application. These events need to be established on page load. If you need certain events to be delayed until a component is rendered, you may want to think about encapsulating those actions in the components themselves. It is not a requirement to use controllers at all, it's just a nice way of organizing your code. If you would like to keep the event handling in controllers, it might be a good idea to load all your controllers, and have them wait for components to fire specific events to attach new events to them. Does this help answer your question?

  5. #5
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    101
    Answers
    8
    Vote Rating
    3
    sskow200 is on a distinguished road

      0  

    Default another way...

    another way...


    Looking into it more, if this is a completely desirable function for you even though not recommended, you could do something like this I believe...

    Code:
     var controller = Ext.create('My.app.Controller');
     controller.init()
    While your init() may look like this...

    Code:
    init: function() {
       this.control(
           'myapppanel' : {
                   afterrender: this.onAfterRenderMyAppPanel
           }
       );
    },
    
    onAfterRenderMyAppPanel: function() {
         console.log('Rendered');
    }
    This should in theory initialize your events on demand. Again, this is not recommended, but I believe it can be done this way.

  6. #6
    Sencha User
    Join Date
    Jan 2012
    Posts
    13
    Vote Rating
    0
    tyfab is on a distinguished road

      0  

    Default


    I have to test this ...

    My concern was to see all this file loading in firebug before the application starts.

    I'm just looking for a way to load independant part of the application only when needed.
    At this moment, as soon as i load the controller, every store, model, and views loads at the same time.

    I will test and come back to you with the create and init controller stuff

    fabrice

  7. #7
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Answers
    3500
    Vote Rating
    854
    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

      0  

    Default


    Don't forget you should be doing a build at the end of development so your controller should be included
    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.

  8. #8
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    101
    Answers
    8
    Vote Rating
    3
    sskow200 is on a distinguished road

      0  

    Default Ext.Loader

    Ext.Loader


    This is a different question altogether. You can dynamically load any js files via the Ext.Loader.

    Code:
         Ext.Loader.setConfig({
               paths: {
                     MyAppComponent: '/path/to/my/app/component/dir/'
               }
         })
         
         //load the file from /path/to/my/app/component/dir/controllers/Controller1.js
         Ext.require('MyAppComponent.controllers.Controller1');
         Ext.syncRequire('MyAppComponent.controllers.Controller1');
    http://docs.sencha.com/ext-js/4-0/#!...method-require
    http://docs.sencha.com/ext-js/4-0/#!...od-syncRequire


    NOTE: Since your app component will most likely require additional files, be sure to utilize the 'requires' config in your app component. Example:

    Code:
    Ext.define('MyAppComponent.view.Component1', {
        requires: [
           'MyAppComponent.view.Component2'
       ]
    });
    
    Ext.define('MyAppComponent.controllers.Controller1' {
        views: [
             'MyAppComponent.view.Component1'
        ]
    });
    This way, when you initialize 'MyAppComponent.controllers.Controller1', the loader will automatically look for 'MyAppComponent.view.Component1' which will then cascade to 'MyAppComponent.view.Component2' because they are all dependencies of eachother
    Last edited by sskow200; 17 Feb 2012 at 5:52 AM. Reason: wrong controller name

  9. #9
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Answers
    3500
    Vote Rating
    854
    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

      0  

    Default


    Ext.Loader shouldn't be used in production. Loading individual files is expensive.
    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.

  10. #10
    Sencha Premium Member
    Join Date
    Apr 2011
    Posts
    101
    Answers
    8
    Vote Rating
    3
    sskow200 is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Ext.Loader shouldn't be used in production. Loading individual files is expensive.
    @mitchellsimoens

    I wholeheartedly agree with you. However, there are use cases where this functionality is desirable in a production environment. Just providing some light on the subject.

Thread Participants: 2