View Full Version : Ext.app.Controller - why getter is called right after being added to controller?

28 Jun 2012, 4:52 AM
See the last line in the createGetters method...

Why is the newly created getter called right after being added to the controller instance?

I thought he application would be the first to call the getter, but this is not the case.

If the ref describing the getter has the autoCreate or forceCreate config, this will immediately create components, which might be not desired.

Ext.define('Ext.app.Controller', {

createGetters: function(type, refs) {
type = Ext.String.capitalize(type);

var i = 0,
length = (refs) ? refs.length : 0,
fn, ref, parts, x, numParts;

for (; i < length; i++) {
fn = 'get';
ref = refs[i];
parts = ref.split('.');
numParts = parts.length;

// Handle namespaced class names. E.g. feed.Add becomes getFeedAddView etc.
for (x = 0 ; x < numParts; x++) {
fn += Ext.String.capitalize(parts[x]);

fn += type;

if (!this[fn]) {
this[fn] = Ext.Function.pass(this['get' + type], [ref], this);
// Execute it right away
this[fn](ref); // <--- why the getter is called here?

28 Jun 2012, 6:55 AM
I figured out the answer, so don't bother :)

28 Jun 2012, 7:25 AM
Would be nice if you share the answer, for the benefit of other people...

28 Jun 2012, 7:41 AM
Would be nice if you share the answer, for the benefit of other people...

Getters listed on the models, controllers and views config are called immediately (I don't know why).

See the Ext.app.Controller.createGetters method.

Getters listed on the refs config are NOT called immediately. They are called for the first time by the application.

See the Ext.app.Controller.ref method.