roger.spall
6 Jan 2012, 10:39 AM
I am really trying to get a grip with best practices for managing my application classes and need some help, pointers, references, etc.
Right now, I have all of my classes in a single root directory, namely..
\myApp\src
Meanwhile, all my classes start with my package name, e.g. 'mypackage.ClassName'
In my main js file I then configure the classloader...
Ext.Loader.setConfig({
enabled: true
});
Ext.Loader.setPath("mypackage", "src");
And everything works just fine in my development environment - using what I believe to be called 'dynamic class loading'.
Now I want to deploy to production, and have been reading that you shouldn't use 'dynamic class loading' for production and should instead create a single 'myClasses-all.js' file which contains all the classes and is then included in the 'top html' file. Lets ignore minifying js for now.
So, I concatenated all of my js files into a single myClasses-all.js file and include the file at the top level.
Now the fun starts!
If I turn off the dynamic class loading (Ext.Loader.setConfig({enabled: false});) my code stops working and complains about missing classes! Two issues seem to raise their ugly head:
1) Inheritance
Obviously some of my classes extend others, but they are not concatenated into the 'all file' in the order of inheritance (namely root class first, followed by sub classes). So ExtJs finds my ClassB which extends ClassA BEFORE it has found ClassA in my 'all file'
** How do I build my 'all file' with the classes in inheritance order?
2) Requires
Some of my classes use the 'requires: ['class','class'] syntax to specify dependencies. Again, if a class specifies a 'requires' for a class which appears below it in the 'all file' then it cannot find it!
** With the possibility of circular dependencies, I don't see how you can ever 'automatically' order the classes in the 'all file' to account for requires?
** What is the best practice for defining 'requires' in class definitions?
If I turn dynamic class loading on and still keep the 'all file' then my code works, but I see a lot of network traffic requesting the individual classes as the 'all file' is loaded. I am assuming this is because the 'all file' cannot resolve certain classes because of the above problems, and therefore the loader goes out and dynamically loads the classes?
What are the best practices for class loading, building 'all files' and using requires in class definitions?
Thanks in Advance.
Right now, I have all of my classes in a single root directory, namely..
\myApp\src
Meanwhile, all my classes start with my package name, e.g. 'mypackage.ClassName'
In my main js file I then configure the classloader...
Ext.Loader.setConfig({
enabled: true
});
Ext.Loader.setPath("mypackage", "src");
And everything works just fine in my development environment - using what I believe to be called 'dynamic class loading'.
Now I want to deploy to production, and have been reading that you shouldn't use 'dynamic class loading' for production and should instead create a single 'myClasses-all.js' file which contains all the classes and is then included in the 'top html' file. Lets ignore minifying js for now.
So, I concatenated all of my js files into a single myClasses-all.js file and include the file at the top level.
Now the fun starts!
If I turn off the dynamic class loading (Ext.Loader.setConfig({enabled: false});) my code stops working and complains about missing classes! Two issues seem to raise their ugly head:
1) Inheritance
Obviously some of my classes extend others, but they are not concatenated into the 'all file' in the order of inheritance (namely root class first, followed by sub classes). So ExtJs finds my ClassB which extends ClassA BEFORE it has found ClassA in my 'all file'
** How do I build my 'all file' with the classes in inheritance order?
2) Requires
Some of my classes use the 'requires: ['class','class'] syntax to specify dependencies. Again, if a class specifies a 'requires' for a class which appears below it in the 'all file' then it cannot find it!
** With the possibility of circular dependencies, I don't see how you can ever 'automatically' order the classes in the 'all file' to account for requires?
** What is the best practice for defining 'requires' in class definitions?
If I turn dynamic class loading on and still keep the 'all file' then my code works, but I see a lot of network traffic requesting the individual classes as the 'all file' is loaded. I am assuming this is because the 'all file' cannot resolve certain classes because of the above problems, and therefore the loader goes out and dynamically loads the classes?
What are the best practices for class loading, building 'all files' and using requires in class definitions?
Thanks in Advance.