Download Get the PDF - Docs
Transcript
qooxdoo Documentation, Release 1.6.1
Init values
Init values are supported by all properties. These values are stored separately by the property engine. This way it is
possible to fallback to the init value when property values are being reset.
Defining an init value
There are two ways to set an init value of a property.
Init value in declaration The preferred way for regular init values is to simply declare them by an init key
in the property configuration map. You can use this key standalone or in combination with nullable and/or
inheritable.
properties : {
myProperty : { init : "hello" }
}
Init value in constructor Alternatively, you could set the init value of the property in the constructor of the class.
This is only recommended for cases where a declaration of an init value as explained above is not sufficient.
Using an initializing function this.initMyProperty(value) in the constructor would allow you to assign
complex non-primitive types (so-called “reference types” like Array, Object) that should not be shared among
instances, but be unique on instance level.
Another scenario would be to use a localizable init value when internationalizing your application: Because
this.tr() cannot be used in the property definition, you may either use the static qx.locale.Manager.tr()
there instead, or use this.tr() in the call of the initializing function in the constructor.
Note: You need to add a deferredInit:true to the property configuration to allow for a deferred initialization
for reference types as mentioned above.
qx.Class.define("qx.MyClass", {
construct: function() {
this.initMyProperty([1, 2, 4, 8]);
},
properties : {
myProperty : { deferredInit : true}
}
};
Applying an init value
It is possible to apply the init value using an user-defined apply method. To do this call the init method
this.initMyProperty(value) somewhere in your constructor - this “change” will than trigger calling the
apply method. Of course, this only makes sense in cases where you have at least an apply or event entry in the
property definition.
If you do not use the init method you must be sure that the instances created from the classes are in a consistent state.
The getter will return the init value even if not initialized. This may be acceptable in some cases, e.g. for properties
without apply or event. But there are other cases, where the developer needs to be carefully and call the init method
because otherwise the getter returns wrong information about the internal state (due to an inconsistency between init
and applied value).
3.2. Properties
87
Related documents
Offline Manual - Docs
1.5.x - Docs
Tester Bench [BETA] User Manual
Offline Manual - Docs
3.5.x - Docs
Offline Manual - Docs
qooxdoo Documentation
qooxdoo Documentation
Version 6.5 End-user manual Last revision: June 29
YAWL - User Manual
Featured Blog User Manual
Techcraft e-Newsletter Volume 38 June 2008.