View Full Version : Managing Dependences between Classes

4 Feb 2013, 3:04 AM
Hi all, I had a .jsp page tha generate a Ext Class like:

<script src="ext/ext-dev.js"></script>
<script src="app.js"></script>
Ext.define('ApplicationData', {
singleton: true,
contextPath: '<%=request.getContextPath()%>'

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:

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?

6 Feb 2013, 2:51 PM
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.

6 Feb 2013, 11:52 PM
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.