View Full Version : Can anyone explain the "requires" system?

11 Jul 2012, 11:43 PM
How exactly does "requires" work and is there best practice?

I'm assuming once ANY class has required the file, it is then available to create from any other class?

So, I could "globally" declare everything in my viewport "ApplicationContainer" class and no need from there on in?

Its probably best practice to declare explicitly what's needed in each class by each class?

How does ExtJS manage this internally?

12 Jul 2012, 12:13 AM
Required means that it will load the js file with your class definition on demand. In the required array you put the names of your classes you need. The Loader will then look in the app/ model/ view/ controller directory structure for the file.

Its like the import directive in java, or using directive in C#.

Views, controllers, models properties do actually the same. If you put classnames there it will also be loaded like the required property.

The best thing to do is loading the classes in that point of your application where you really need them. If you load them in the top section like the application, it can cause overhead. For example if you need a class just for openening a window, you can set the required class in that part of you app.

In my own app, I do not use required, but I bundle all js files I need for the application. This because, a larger bundle (all js files in one file) has still a better performance than multiple requests to the server loading all these small js files.