new module:ct-trading /statemachine /State Machine(oState Model)
Constructs a StateMachine
that uses the specified StateModel
to
determine which transitions are possible from the current state.
A StateMachine
tracks state and manages transitions between them.
Parameters:
Name | Type | Description |
---|---|---|
oStateModel |
module:ct-trading |
The statemodel for this statemachine. May not be null. |
Methods
add State Changed Listener(state Changed Listener)
Adds a listener that will be notified any time the state of this statemachine changes.
Parameters:
Name | Type | Description |
---|---|---|
stateChangedListener |
module:ct-trading |
The listener that wishes to be notified of state changes. May not be null or undefined. |
Throws:
-
if the listener is not a non-null instance of StateChangedListener.
- Type
-
module:ct-core
/Error
add Trigger Active Changed Listener(listener, event Name)
Adds a listener that will be notified any time the supplied trigger goes from active to inactive or inactive to active. A trigger is considered active if there is an event that would trigger a transition from the current state given the supplied context.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener that wishes to be notified of possible state changes. May not be null or undefined. |
eventName |
String | The Event that we're interested in. Must be a non-null string. |
Throws:
-
if the listener is not a non-null instance of StateChangedListener.
- Type
-
module:ct-core
/Error
get Current State() → {module:ct-trading /statemachine /State}
Gets the current state that the state machine is in.
Returns:
The current module:ct-trading/statemachine/State
of this Statemachine. Will not be null.
get Name() → {String}
Returns the name that this state machine represents.
Returns:
The state machine name
- Type
- String
get State Model() → {String}
Returns the state model the state machine is an instance of.
Returns:
The state model
- Type
- String
has Transition(sEvent) → {boolean}
Validate if the transition is valid.
Parameters:
Name | Type | Description |
---|---|---|
sEvent |
Returns:
- Type
- boolean
process Event(sEvent, oContext) → {module:ct-trading /validation /Validation Result}
Attempts to change the state to a new state, following a transition defined as being activated by the supplied Event. If the validators pass, it will change state. If they do not pass, the state will remain the same.
Parameters:
Name | Type | Description |
---|---|---|
sEvent |
String | The event that triggers a transition to a new state. |
oContext |
Object | The data to be validated - indicating whether or not the transition is allowed. |
Throws:
-
if the Event is not a non-null string, If context is null or undefined, if the Event doesn't lead to a state from the current state, or if any of the validators throws an exception.
- Type
-
module:ct-core
/Error
Returns:
The result of checking the validations for the transition associated with this Event.
process Event Without Validation(sEvent) → {boolean}
Bypass event validation that can be redundant.
Parameters:
Name | Type | Description |
---|---|---|
sEvent |
Returns:
- Type
- boolean
remove State Changed Listener(state Changed Listener)
Removes a StateChangedListener.
Parameters:
Name | Type | Description |
---|---|---|
stateChangedListener |
module:ct-trading |
The listener that no longer wishes to be notified of state changes. May not be null or undefined. |
Throws:
-
if the listener is not a non-null instance of StateChangedListener.
- Type
-
module:ct-core
/Error
remove Trigger Active Changed Listener(listener, sEvent)
Removes the specified listener from the list of those to be notified when the specified event triggers a transition from one state to another.
Parameters:
Name | Type | Description |
---|---|---|
listener |
module:ct-trading |
The listener that no longer wants to be notified of possible state changes. May not be null or undefined. |
sEvent |
String | The Event that we're no longer interested in. Must be a non-null string. |
Throws:
-
if the listener is not a non-null instance of StateChangedListener.
- Type
-
module:ct-core
/Error
test Context(oContext)
Tests a specific context against the current state. If this new context would change the result of calling any validators
- i.e. some transitions that under the previously tested context could not be followed can, under the supplied context be followed (or vice versa) - then all the TriggerActiveChangedListeners associated with the Event that would give a different result to before are notified.
A concrete example is an execute button. It wants to be told any time the situation of the Execute trigger changes.
Parameters:
Name | Type | Description |
---|---|---|
oContext |
Object | the data context. May not be null or undefined. |