Ext.define('...', {
uses: ['...'],
});
and
Ext.define('...', {
requires: ['...'],
});
I am a bit confused...Do they have common ground at all? When do we use one or the other?
Ext.define('...', {
uses: ['...'],
});
and
Ext.define('...', {
requires: ['...'],
});
I am a bit confused...Do they have common ground at all? When do we use one or the other?
Share Improve this question asked Apr 17, 2013 at 3:03 TomTom 16.2k15 gold badges74 silver badges115 bronze badges 1- FWIW, Mitchell Simoens has a good blog post about this topic. – arthurakay Commented Jun 25, 2015 at 20:39
2 Answers
Reset to default 14It's pretty much covered by the documentation:
Uses are optional class dependencies that are used by, but not required by, a class. These can be loaded asynchronously and do not have to be available for the class to be instantiated.
For example, if it's something your class instantiates Foo in the constructor, then it should be in requires
.
If it instantiates Foo in some method that might get called later by the developer, it could go in uses
.
'requires' are needed to create a class, 'uses' are needed to create an object of that class.
The event sequence is:
- Ext.define is called
- 'requires' and 'uses' are enqueued to be loaded asynchronously
- class is created when all its 'requires' are loaded
- Ext.onReady listeners are called when all classes' 'requires' and 'uses' are loaded