PDA

View Full Version : Difference between applyX, updateX, setX, and doSetX?



jtb4x
25 Jan 2013, 9:27 AM
where X is some variable in a class's config

Can someone give me a rundown of what the difference between them is? As far as I can tell from docs, applyX happens before setX when calling setX, but other than that, I'm not sure.

Thanks

mitchellsimoens
28 Jan 2013, 8:09 AM
I'm assuming you are talking about the config object system. Little disclaimer, the framework doesn't use this internally but you can use it in your application code.

If you have this in your Ext.define code:

config : {
foo : 'bar'
}

and of course called initConfig in the constructor your class will now have a getFoo and setFoo method. The getFoo will return the foo property but the setFoo is more advanced than that.

When setFoo is executed, it will check if applyFoo method exists. If so then it will execute it where it expects something returned. setFoo will then set the value onto the foo property. It will then check if updateFoo exists and if so then will execute it and this ends what setFoo will do. If that wasn't understandable then maybe this code:


setFoo : function(value) {
var oldValue = this.foo;

if (this.applyFoo) {
value = this.applyFoo(value, oldValue);
}

this.foo = value;

if (this.updateFoo) {
this.updateFoo(value, oldValue);
}
}

applyFoo is often used to transform the value being passed and updateFoo is to take action on the new value.