Class: State

State

new State(name, data)

Parameters:
Name Type Argument Description
name String
data Object <optional>
object with configuration data, see jsfsa.State#parseData for syntax
Source:

Members

fqn :String

Source:

isInitial :Boolean

Whether this state will be used as the initial state of the jsfsa.State#parent
Source:

name :String

The name of the state
Source:

parent :String

Name of the parent state
Source:

Methods

addGuard(action, guard) → {jsfsa.State}

Sets up guard to be called if entry/exit of a state has been requested.
The guard should return true to allow the action to happen. Anything falsy will deny transition to/from this state.
The guard receives a jsfsa.StateEvent object as a first parameter.
Parameters:
Name Type Description
action String One of the static property values of jsfsa.Action
guard Function
Source:
See:
  • jsfsa.State#addGuards
  • jsfsa.State#hasGuard
  • jsfsa.State#removeGuard
Returns:
the instance of jsfsa.State that is acted upon
Type
jsfsa.State

addGuards(action, guards) → {jsfsa.State}

Registers multiple guards to be called on action
Parameters:
Name Type Description
action String One of the static property values of jsfsa.Action
guards Function[]
Source:
See:
  • jsfsa.State#addGuard
  • jsfsa.State#hasGuard
  • jsfsa.State#removeGuard
Returns:
the instance of jsfsa.State that is acted upon
Type
jsfsa.State

addTransition(transitionName, stateName) → {jsfsa.State}

Tells this state to allow a transition with name transitionName from this state to stateName
Overwrites transitions with the same name already registered with this state.
Parameters:
Name Type Description
transitionName String
stateName String
Source:
See:
  • jsfsa.State#removeTransition
  • jsfsa.State#hasTransition
  • jsfsa.State#getTransition
Returns:
the instance of jsfsa.State that is acted upon
Type
jsfsa.State

destroy()

Releases all resources. After calling this method, the State instance can/should no longer be used.
Source:

getTransition(transitionName) → {String}

Retrieves the name of the state that will be transitioned with transitionName
Parameters:
Name Type Description
transitionName String
Source:
See:
  • jsfsa.State#addTransition
  • jsfsa.State#hasTransition
  • jsfsa.State#removeTransition
Returns:
target state name
Type
String

hasGuard(action, guard) → {Boolean}

Checks if a guard has been registered to control transitioning to/from this state.
Parameters:
Name Type Description
action String One of the static property values of jsfsa.Action
guard Function
Source:
See:
  • jsfsa.State#addGuard
  • jsfsa.State#addGuards
  • jsfsa.State#removeGuard
Returns:
Type
Boolean

hasTransition(transitionName) → {Boolean}

Checks whether a transition with transitionName has been registered for this state.
Parameters:
Name Type Description
transitionName String
Source:
See:
  • jsfsa.State#addTransition
  • jsfsa.State#getTransition
  • jsfsa.State#removeTransition
Returns:
Type
Boolean

parseData(data)

Parses the data to configure the state.
Parameters:
Name Type Description
data Object
Source:
Examples
 //Strict syntax
    var guard = function( e ){
        return false;
    };
    var listener = function( e ){
        console.log( e );
    }
    var config = {
        isInitial : true,
        transitions : {
            'ignite' : 'on', //transitionName : targetStateName
            'fail' : 'broken'
        },
        guards : {
            entry : [ guard ],
            exit : [ guard ]
        },
        listeners : {
            entryDenied : [ listener ],
            entered : [ listener ],
            exitDenied : [ listener ],
            exited : [ listener ]
        }
    }
 //Loose syntax
    var guard = function( e ){
        return false;
    };
    var listener = function( e ){
        console.log( e );
    }
    var config = {
        isInitial : true,
        'ignite' : 'on', //transitionName : targetStateName
        'fail' : 'broken'
        guards : {
            entry : guard,
            exit : guard
        },
        listeners : {
            entryDenied : listener,
            entered : listener,
            exitDenied : listener,
            exited : listener
        }
    }

removeGuard(action, guard) → {jsfsa.State}

Unregisters a guard for action
Parameters:
Name Type Description
action String One of the static property values of jsfsa.Action
guard Function
Source:
See:
  • jsfsa.State#addGuard
  • jsfsa.State#addGuards
  • jsfsa.State#hasGuard
Returns:
the instance of jsfsa.State that is acted upon
Type
jsfsa.State

removeTransition(transitionName) → {jsfsa.State}

Removes a registered transition with name transitionName. Fails silently if such a transition was not found.
Parameters:
Name Type Description
transitionName String
Source:
See:
  • jsfsa.State#addTransition
  • jsfsa.State#hasTransition
  • jsfsa.State#getTransition
Returns:
the instance of jsfsa.State that is acted upon
Type
jsfsa.State