Title here
Summary here
Trait
This class represents an helper for any object that needs to have states.
Important:
Kind: global mixin
Extends: Trait
Properties
Name | Type | Description |
---|---|---|
_state | number | current state |
Example
Class.declare("AbstractClassWithStates", {
traits: [$MObjectStates],
statics: {
STATE_READY: 0,
STATES: ["STATE_READY"]
},
constructor: function(properties) {
this.setStateByName("STATE_READY");
}
});
$AbstractClassWithStates.declare("MyClassWithStates", {
statics: {
STATE_READY: $AbstractClassWithStates.STATE_READY,
STATE_ERROR:1,
STATES: $AbstractClassWithStates.STATES.concat(["STATE_ERROR"])
}
});
var instance = $MyClassWithStates();
instance.getState(); // $MyClassWithStates.STATE_READY
instance.getStateByName(); // STATE_READY
instance.setState($MyClassWithStates.STATE_ERROR);
instance.setStateByName("STATE_ERROR");