1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    16
    Vote Rating
    1
    elettronik is on a distinguished road

      0  

    Default Answered: Managing Dependences between Classes

    Answered: Managing Dependences between Classes


    Hi all, I had a .jsp page tha generate a Ext Class like:

    Code:
    <script src="ext/ext-dev.js"></script>
    <script src="app.js"></script>
    <script>
        Ext.define('ApplicationData', {
            singleton: true,
            contextPath: '<%=request.getContextPath()%>'
        }):
    </script>
    in my app.js I initialze Ext.application() in Ext.onReady, and also I require all required classes. This work well until required classes are loaded by dynamic loader, but when I compile classes using sencha cmd I cannot instantiate some of my required classes, since it depend on the ApplicationData member. The class is like:

    Code:
    Ext.define('MyApp.store.MyStore', {
        requires: ['ApplicationData'],
    
        proxy: {
            type: 'ajax',
            url: ApplicationData.contextPath + '/store'
        }
    });
    In fact, afte compilation with sencha cmd the url memeber is defined as url: 'undefined/store' Is the only solution initialize url in constructor?
    Last edited by elettronik; 4 Feb 2013 at 3:06 AM. Reason: Clarification

  2. The issue with that is that MyApp.store.MyStore won't be defined before the ApplicationData class is loaded and define/instantiated which is exactly what you want. However, the browser has already eval'd the file for the MyStore and found that ApplicationData does not exist. In a build this will indeed work but during development since the ApplicationData does not exist before the MyStore's file is eval'd by the browser it will not work. To get around this, you would have to Ext.require ApplicationData in app.js so it loads before the MyStore is loaded or define the proxy in the constructor method of MyStore.

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


    The issue with that is that MyApp.store.MyStore won't be defined before the ApplicationData class is loaded and define/instantiated which is exactly what you want. However, the browser has already eval'd the file for the MyStore and found that ApplicationData does not exist. In a build this will indeed work but during development since the ApplicationData does not exist before the MyStore's file is eval'd by the browser it will not work. To get around this, you would have to Ext.require ApplicationData in app.js so it loads before the MyStore is loaded or define the proxy in the constructor method of MyStore.
    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.

  4. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    16
    Vote Rating
    1
    elettronik is on a distinguished road

      0  

    Default


    In the end I solved problem by putting proxy url in constructor, but the situation for me is the opposite of what you said: during development I load MyStore, after onReady event since that view is loaded as dependency of already loaded class. But during the build the class will be packed on a file that is loaded before onReady event, so the problem in production version.
    Hope this will help someone other.

Thread Participants: 1

Tags for this Thread