Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sencha Ext.define Uses vs Requires

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?

like image 415
Tom Avatar asked Apr 17 '13 03:04

Tom


People also ask

What is requires Ext JS?

Requires - All classes required to be defined for the class to be instantiated. Uses - A list of classes potentially used by the class at some point in its lifecycle, but not necessarily requried for the class to initially be instantiated. Subclasses - Classes that extend the current class.

What is the use of Ext?

Ext JS is a popular JavaScript framework which provides rich UI for building web applications with cross-browser functionality. Ext JS is basically used for creating desktop applications. It supports all the modern browsers such as IE6+, FF, Chrome, Safari 6+, Opera 12+, etc.

Is Sencha Ext JS free?

It is a free, limited commercial use license, with robust Ext JS Frameworks, hundreds of modern components, a material theme, and more to develop stunning-looking apps.


2 Answers

It'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.

like image 175
Evan Trimboli Avatar answered Sep 27 '22 17:09

Evan Trimboli


'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
like image 26
java4script Avatar answered Sep 27 '22 19:09

java4script