1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    200
    Answers
    11
    Vote Rating
    4
    dedoz is on a distinguished road

      0  

    Default Unanswered: How to work with non MCV classes

    Unanswered: How to work with non MCV classes


    I have a class that is not a controller or a view, and i want to be present in all my code, is like a util class.
    So i did this

    main.js
    Code:
    Ext.create('Ext.app.Application', {
            name: 'MUI',    
            appFolder: 'app',
            controllers : ['SomeController1','OtherController2'],
            autoCreateViewport: true, 
            launch: function()
            {    
                MUI.currentUser = Ext.create('MUI.util.currentUser');    
            }
        });
    on a file in app/util/currentUser.js
    Code:
    Ext.define('MUI.util.currentUser',{
        ... some code will go here ...
    });
    So i create a instance of this currentUser class (its dymanic loaded ) and save the reference in my app namspace like MUI.currentUser.

    Its this the correct way to do this ?
    Also i have a problem, while it will be present for every controller method, i wont be available in the init method of those controllers i define in the aplication controllers : ['SomeController1'] since this init method is executed before my application launch method. Happens the same in any excuted code before the app launch, like while defining a view.

    How can i have some objects that are present in my whole app ?

    I dont want to set a property in the application controller because i can go into name colision doing something like
    Code:
    Ext.create('Ext.app.Application', {
            name: 'MUI',    
            appFolder: 'app',
            controllers : ['SomeController1','OtherController2'],
            autoCreateViewport: true, 
            currentUser : Ext.create('MUI.util.currentUser'),
            otherHelperObject1 : Ext.create('MUI.util.helper1'),
            otherHelperObject2 : Ext.create('MUI.util.helper2'),
            launch: function()
            {  
                
            }
        });
    besides i dont know if ill always get a reference to the app, i know in the controller we can do something like this.application.currentUser, but while defining a view ? i wont get the this.application

    Should i do this ?
    Code:
    Ext.onReady(function() {
        MUI = {}
        MUI.currentUser = Ext.create('MUI.util.currentUser');
      
        Ext.create('Ext.app.Application', {
            name: 'MUI',   
            appFolder: 'app',
            controllers : ['SomeController1','OtherController2'],
            autoCreateViewport: true, 
            launch: function()
            {                
            }
        });
    
    });
    this seems to work but im not sure its the best way

    (sorry for my bad english)

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,704
    Answers
    3357
    Vote Rating
    751
    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


    I would use Ext.require and setup a path to it:

    Code:
    Ext.Loader.setPath('MUI', 'app');
    
    Ext.require([
        'MUI.util.currentUser'
    ]);
    This will expect the MUI.util.currentUser to be in the app/util/currentUser.js file.
    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
    Dec 2011
    Posts
    200
    Answers
    11
    Vote Rating
    4
    dedoz is on a distinguished road

      0  

    Default


    yeah i know that but ¿where to put the reference to the object created from that class? so that object is available on all my code, that includes
    the init controller method
    the views definition (Ext.define(MUI.view.SomeView)
    etc

    As a app config property ?
    currentUser : Ext.create('MUI.util.currentUser'), and i explained in the initial post
    This works for the controller init method (it will be avaible there) but not in the views definition.


    Or under the MUI namespace ? like MUI.currentUser = Ext.create('MUI.util.currentUser');
    and where to put this line ,
    1) inside the app launch method doesnt work because i wont be avaible on controllers init or in view definition

    2) Before Ext.create('Ext.app.Application'....
    this is the best option i got, now is available on all my code (views, models, controllers, etc) but the problem is i dont get the facilities of dyamic loading so i have to declare each class/file im using on this util classes

    so derives in this
    main.js
    Code:
    Ext.Loader.setPath('MUI.util.currentUser', 'app/util/currentUser.js');
    Ext.require(['MUI.util.currentUser']);
    
    Ext.onReady(function() {
        MUI = {}
        MUI.currentUser = Ext.create('MUI.util.currentUser');
        
        Ext.create('Ext.app.Application', {
            name: 'MUI',    
            appFolder: 'app',
            controllers : ['controller1','controller2'],
            autoCreateViewport: true, 
            launch: function()
            {    alert("getName from launch :"+ MUI.currentUser.getName);
                // Works
            }
        });
    });
    in controller1 init method
    Code:
    Ext.define('MUI.controller.controller1', {
        extend: 'Ext.app.Controller',
        views : [view1],
        init: function() {
            alert("getName from controller init method :"+ MUI.currentUser.getName);
            // works
        }
    });
    in view1 definition
    Code:
    Ext.define('MUI.view.Viewport', {
        extend: 'Ext.container.Viewport',
        items: [{
            html: 'My App Title - User : '+ MUI.currentUser.getName,  // works
        }]
    });
    the only problem is i dont get the dynamic loading magic in my util classes

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar