1. #1
    Sencha User xava's Avatar
    Join Date
    Mar 2009
    Location
    Argentina
    Posts
    36
    Vote Rating
    0
    xava is on a distinguished road

      0  

    Default Controllers, View in requires: [] and App performance

    Controllers, View in requires: [] and App performance


    Hello,
    i am quite new working with Ext 4.2 MVC,
    and i'm a bit obsessive on best practice and app performance

    then, now i have a dilemma

    i have a typical principal App ToolBar with menuItems, almost all the item action have a own controller that open a window.Window component and perfom the logic

    the main controller listen the menuItem event and when a item is clicked), the main controller:

    1) load the item controller (this.getController(itemController))
    2) define this.control for the item view
    3) the itemController load the window.Window view

    in the itemController i put in requiere the itemView,
    but when i load manually the itemController i get a console message: "[Ext.Loader] Synchronously loading 'AF.controller.menu.client.NewClient'; consider adding Ext.require('AF.controller.menu.client.NewClient') above Ext.onReady"

    - if i load all my controller like the console message told me i have more performance in the Application than loading every one when i need it?

    - i see that later that i load a itemController, if i click again in this menuItem the controller are still loaded, i have some way to remove a loaded controller?

    - finally and like a resume, what is more efficient: load all aplicacion controller in require or load manually when you need it?

    thanks you

  2. #2
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    122
    Vote Rating
    7
    chamacs is on a distinguished road

      1  

    Default


    The 'warning message' is because that specific class definition had not been loaded from the server up front. You really do want to load all class definitions upfront. For performance in a production environment you should use the Sencha SDK to combine and minify all your app classes into a single JS file.
    ----------
    The way the MVC works is that only a single instance of any specific controller is needed. So you shouldn't have any overhead associated with multiple instances of controllers. All controllers needed at app start up should be defined in the Application class 'controllers' array. By doing this the controllers are created and initialized. (The 'init' method is where the this.control() call needs to be because it can only be called once otherwise duplicate event handlers are added to views).

    If you do not want to auto-create the controller instance, add it to the 'uses' attribute of the class. This will ensure the class definition is loaded upfront, but will not auto-create an instance. The drawback to doing this with a controller is that 'creating an instance' yourself, does not initialize the controller (i.e. no automatic call to the 'init' method). You must handle this yourself.

    My implementation (in a base controller class):

    Code:
        init : function() {
        	// Custom attribute to know it has been initialized
        	this.initialized = true;
        },
        
        /**
         * Controllers only need to be initialized once.
         * This convenience method will handle the init check.
         * 
         * @param name
         * @returns controller reference
         */
        initializeController : function(name) {
        	var controller = this.getController(name);
        	// Only init the controller the first time
        	if (!controller.initialized) {
        		controller.init();
        	}
        	return controller;
        },
    Hope this helps.

  3. #3
    Sencha User xava's Avatar
    Join Date
    Mar 2009
    Location
    Argentina
    Posts
    36
    Vote Rating
    0
    xava is on a distinguished road

      0  

    Default


    i get it!

    i am using the Cmd SDK, so is better load all controllers in app.js and if i dont want that the init() auto run, i can use your code

    and later when i do a #sencha build put all together in one file

    thanks you

Thread Participants: 1