Reputation: 2976
Ext.define('Algo.data.Simulated', {
requires: [
//....
],
onClassExtended: function (cls, data) {
// ....
}
})
Here is the code. I cannot find any documentation about it on Sencha's website. Also, what do cls and data mean?
Upvotes: 0
Views: 215
Reputation: 20224
Well, the easy way to find out would be to define a new class, override onClassExtended, and use two console.log
to log the values.
But let's take the hard way, searching the ExtJS codebase for onClassExtended
. Notepad++ does provide a search that can find a string in all files in a directory, that's really useful with ExtJS.
You will find that the property is first processed in packages\core\src\class\Class.js
, l. 347 ff., and that the processing does nothing but add the function to $onExtended
.
So we search for $onExtended
, finding that usually, $onExtended
is called in triggerExtended()
, which is called from, you guess it, packages\core\src\class\Class.js
, l. 347 ff. (but it is called BEFORE the current class's onClassExtended
is added to the list!)
Class.triggerExtended.apply(Class, arguments);
together with
function(Class, data, hooks) {
means that cls
will contain whatever is in Class
, and data
will contain whatever data
has been put into the extend method.
Looking at the code, I believe that these two parameters are the two parameters of Ext.define
:
Ext.define(
'MyApp.data.Test', // <- Class
{ // data object
extend:'Ext.class.Base' // <- "data.extend" is deleted in line 357
...
}
);
It seems onClassExtended
does allow you to define, in EVERY class in a hierarchy, a processing directive that can transform the class definition. They are executed, beginning with the topmost (the most special class) and ripple through until they reach the base class, Ext.class.Base
.
Unlike the constructor, these transformations are executed during definition of a child class, not during instance creation.
Upvotes: 3