That's to avoid cyclic dependencies.
Consider the following example:
src/Foo.js
Ext.define('Test.Bar', {
requires: 'Test.Foo'
}, function() {
console.log('Loaded Bar');
});
src/Bar.js
Ext.define('Test.Foo', {
requires: 'Test.Bar'
}, function() {
console.log('Loaded Foo');
});
app.js
Ext.Loader.setConfig({
enabled: true
,paths: {
Test: 'src'
}
});
Ext.require('Test.Foo');
Ext.onReady(function() {
alert('Everything\'s loaded!');
});
The alert will never fires. If you tries that with a dev build (eg. ext-all-dev.js
), the loader will tell you why:
> Uncaught Error: Deadlock detected while loading dependencies! 'Test.Foo' and 'Test.Bar' mutually require each other. Path: Test.Foo -> Test.Bar -> Test.Foo
Replaces the requires
with uses
in any of the two classes, and problem solved, alert shooting.
To address the last part of your question, you should avoid using Ext.create
completely... In part for performance reasons, but especially because in dev mode, while the dynamic Loader is enabled, you won't notice missing requires
if you use it. And that may cost you some time to find all the missing one when you'll try to compile your app... While this will cause a crash you can't miss:
new My.Class();