====== Using the State Machine ====== In a rich client application, it is often useful to track the current state of an application, such as "logged in" or "unauthenticated". Entourage provides a State Machine component to enable this programming technique, and allow you to create stateful client applications in the web browser. **Live Example**
Waiting for message...
==== App.StateMachine(name) ====
Create a new State Machine with the given name.
var my_state_machine = App.StateMachine('state_machine');
^ Parameter ^ Description ^
| name | A string which is the name of the state machine. |
\\
==== addState(state,trigger,active) ====
Add a state to the state machine.
my_state_machine.addState('a_state','l:message[name=value,name2!=value]', false);
^ Parameter ^ Description ^
| state | A string which is the the name of the state. |
| trigger | A string which defines message and any parameters to trigger the state change. Takes the form of ''l:message[name=value,name2!=value]''. |
| active | A boolean identifying if the state should become the active state. |
\\
==== addListener(callback) ====
Adds a listener to the state machine.
my_state_machine.addListener(function(){
// ...
});
^ Parameter ^ Description ^
| callback | A function that will be called when the state machine state changes. |
\\
==== fireStateChange(state) ====
Changes the state machine's state to the passed in state.
my_state_machine.fireStateChange('a_state');
^ Parameter ^ Description ^
| state | A string which is the the name of the state to fire. |
\\
==== getActiveState() ====
Returns the active state.
my_state_machine.getActiveState();
\\
==== setActiveState(state) ====
Another way to call ''fireStateChange(state)''.
my_state_machine.setActiveState('a_state');
^ Parameter ^ Description ^
| state | A string which is the the name of the state to fire. |