Reputation: 1800
How can I create config members with a getter
or setter
only but not both at the same time?
By default it creates both a getter
and setter
.
Ext.define('Myapp.myclass', {
config: {
conf1 : true, // Make this only have setter.
conf2 : false // Make this only have getter.
},
constructor: function(config) {
this.apply(config);
}
});
Upvotes: 0
Views: 268
Reputation: 5054
Configs actually create 4 helper methods, which are quite useful.
_config1 this is where the value gets saved
getConfig1 gets you the value
applyConfig1 allows you to check if the setter value is valid
updateConfig1 do some stuff to dom elements
setConfig1 call applyConfig1 and updateConfig1 if available and set the value to _config1. Usually you dont want to touch this, but use updateConfig1
If you do not want these then you have to do the work yourself, but you might not get bindables or other ExtJS out of the box functionality. For me it does not make a lot of sense not to use configs.
Ext.define('Myapp.myclass', {
_conf1: true, // Make this only have setter.
setConfig1: function(value) {
let oldValue = this._config1;
if(oldValue === value) return;
this._config1 = value;
},
_conf2: true, // Make this only have getter.
getConfig2: function() {
return this._config2;
}
});
Upvotes: 1