Allow authors to easily define and use observable properties on a class. It adds observable property definitions to the prototype of an object, creates properties from the prototype definitions in the object initializer, and adds accessors for the property to the prototype.
The V$.cf2.OPProto class contains the following methods.
Adds the named property to the class's prototype object. If the specified class does not yet have the methods from cf2:ObservablePropertySet mixed in, then it will add them too.
It adds a getter method to the prototype that retrieves the value from the underlying observable property. The name of the method will start with 'get', followed by the name of the property with the first letter capitalized. For example, if the property is called 'enabled', then the corresponding getter method will be named getEnabled().
If the property is writable, then it adds a setter method to the prototype that will set the value of the underlying observable property. The name of the method will start with 'set', followed by the name of the property with the first letter capitalized, and will take a single value. For example, if the property is called 'enabled', then the setter method will be named setEnabled(value). The setter will return true if it changed the underlying property, or false otherwise.
Parameter | Description | Type |
---|---|---|
class | The class to which prototype properties the property definition is to be added. | any |
name | The name of the property to add. | String |
options | A set of options that determine how the property is created. | Map |
Initializes the specified object by creating observable properties as defined in the prototype object. Returns the creation results for each created property.
Parameter | Description | Type |
---|---|---|
object | The object that is to be initialized. | any |
// Define a new 'class' Button
function Button(){
// Initialise any observable properties defined on the Button 'class'.
var results = V$.cf2.OPProto.init(this);
// Get the update function for the read-only property.
var update = results.readOnly.update;
}
// Add an observable property definition on the Button 'class'.
// Will also add setEnabled/getEnabled methods.
V$.cf2.OPProto.add(Button, "enabled", {initialValue: true});
V$.cf2.OPProto.add(Button, "readOnly", {initialValue: true});
// Create a new Button.
var b = new Button();
// Get the value of the 'enabled' observable property.
var enabled = b.getEnabled();
>> true
// Set the value of the 'enabled' observable property.
b.setEnabled(false);