PDA

View Full Version : [CLOSED] Ext.app.Application#controllers behave differently from models, stores, views



gianmarco
2 Oct 2011, 5:40 AM
For example, when this class definition is evaluated (using 4.0.2a version):

<pre>
Ext.define('Trackr.app.Login', {
extend: 'Ext.app.Application',
controllers: [ 'MyController' ],
stores: [ 'MyStore' ],
views: [ 'MyView' ],
models: [ 'MyModel' ]
});
</pre>

ExtJS find the following dependencies:

<pre>
[ 'Trackr.model.MyModel', 'Trackr.store.MyStore', 'Trackr.view.MyView', 'Trackr.app.Login' ]
</pre>

As you can see there's no 'Trackr.controller.MyController' included as dependency. This is because 'controllers' config is not evaluated as a preprocessor. This is a problem because:


* a similar set of config property behave differently
* break tool that try to automatically extract dependencies from application code


As a workaround, this work:

<pre>
Ext.define('Trackr.app.Login', {
extend: 'Ext.app.Application',
requires: [ 'Trackr.controller.MyController' ], // Workaround
controllers: [ 'MyController' ],
stores: [ 'MyStore' ],
views: [ 'MyView' ],
models: [ 'MyModel' ]
});
</pre>

mitchellsimoens
2 Oct 2011, 4:52 PM
This is not a bug as the Application isn't dependent on a model or store. A view maybe.

gianmarco
2 Oct 2011, 10:56 PM
I think you didn't get the point.


After the definition of this class


Ext.define('Trackr.app.Login', {
extend: 'Ext.app.Application',
controllers: [ 'MyController' ]
});


Ext.Loader.history doesn't contain 'Trackr.app.MyController'. This is problematic because an automatic tool for discovering application dependencies (like Sencha SDK tool) can't work simply by *defining* the class.
In order for dependency discovery to work, you have to actually *run* the application, but this can have many requirements (a server running, a database and so on) and for this reason the process cannot be easly automated (for example in continuous integration scenario) and is inherently not repeatable.


Note that this code instead


Ext.define('Trackr.app.Login', {
extend: 'Ext.app.Controller',
stores: [ 'MyStore' ]
});


Works as expected, and after class definition you have 'Trackr.store.MyStore' in Ext.Loader.history

mitchellsimoens
3 Oct 2011, 5:01 AM
So Trackr.controller.MyController isn't loaded when the launch method is fired off?

gianmarco
3 Oct 2011, 6:31 AM
When Ext.app.Application#launch is called, the controller class is loaded. However this mean that, in order to discover all dependencies for an application, you need to actually *run* the application.


Please note that running the application is different than loading application classes (loading mean executing Ext.define statements, running mean calling Ext.create on an application class).


The problem is that you can't discover application dependencies unless you actually run the application. With ExtJS new class system this should not be required because the 'require' property is evaluated during Ext.define. This is true also for Ext.app.Controller#stores, Ext.app.Controller#views, Ext.app.Controller#models but *NOT* for Ext.app.Application#controllers


This is IMO the bug