require(["delite/Stateful"], function (Stateful) { new Stateful(); })
Base class for objects that provide named properties with optional getter/setter control and the ability to watch for property changes.
The class also provides the functionality to auto-magically manage getters
and setters for class attributes/properties. Note though that expando properties
(i.e. properties added to an instance but not in the prototype) are not supported.
Getters and Setters should follow the format of _setXxxAttr or _getXxxAttr where the xxx is a name of the attribute to handle. So an attribute of "foo" would have a custom getter of _getFooAttr and a custom setter of _setFooAttr. Setters must save and announce the new property value by calling this._set("foo", val), and getters should access the property value as this._fooAttr.
- Source:
Examples
Example 1
var MyClass = dcl(Stateful, { foo: "initial" });
var obj = new MyClass();
obj.watch("foo", function(){
console.log("foo changed to " + this.foo);
});
obj.foo = bar;
// Stateful by default interprets the first parameter passed to
// the constructor as a set of properties to set on the widget
// immediately after it is created.
Example 2
var MyClass = dcl(Stateful, { foo: "initial" });
var obj = new MyClass({ foo: "special"});
- Source:
Methods
-
mix()
-
Set a hash of properties on a Stateful instance
- Source:
Example
myObj.mix({ foo: "Howdy", bar: 3 })
-
processConstructorParameters()
-
Called after Object is created to process parameters passed to constructor.
- Source:
-
watch()
-
Watches a property for changes.
- Source: