lib/flowBuilder.js
/**
 * Builds action and view states but NOT subflow states
 * @param flowInst
 * @param initObj
 */
Builds action and view states but NOT subflow states
@param flowInst
@param initObj
Builds action and view states but NOT subflow states @param flowInst @param initObj
function buildStates(flowInst, initObj) {
    var flowInstance = flowInst;
    var startStateExists = false;
    flowInst._stateBuilderIndex = flowInst._stateBuilderStartIndex;
    Object.keys(initObj.states).forEach(function(stateName){
        var state = new State(stateName, flowInstance._stateBuilderIndex);
        state.onEntry =  initObj.states[stateName].onEntry;
        state.error =  initObj.states[stateName].error;
        state.type = initObj.states[stateName].type;
        assert(state.type,
            'Invalid flow definition ... State must have type in defintion for state: ' +
                stateName);
        if(state.type === State.types.VIEW) {
            state.viewName = initObj.flowDefinition.states.view[stateName].viewName;
            assert(state.viewName,
                'Invalid flow definition ... view state MUST have view name property: ' +
                    stateName);
        }
        assert(state.onEntry,
            'Invalid flow definition ... missing onEntry from state defintion for state: ' +
                stateName);
        assert.strictEqual(typeof state.onEntry, 'function',
            'Invalid flow def ... onEntry is not a function for state: ' + stateName);
        assert(state.error, 'Must have error defined for a state that is not a subflow state');
        Object.keys(initObj.states[stateName]).forEach(function(key){
            if(typeof key === 'string' && key !== 'onEntry' && key !== 'error' &&  key !== 'type' &&
                typeof initObj.states[stateName][key] === 'function')  {
                state.userDefinedMethods[key] = initObj.states[stateName][key];
            }
        });
        buildStateTransitions(state, initObj);
        flowInstance.endStates.forEach( function(endStateName)  {
            assert(endStateName !== state.name, 'Existing state name and end state name are the same: ' +
                endStateName);
        });
        flowInstance._states[flowInstance._stateBuilderIndex] = state;
        flowInstance._stateBuilderIndex += 1;
        flowInstance._statesByName[state.name] = state;
        if( stateName === flowInstance._startState )
        {
            startStateExists = true;
        }
    });
    flowInst._stateBuilderEndIndex = flowInst._stateBuilderIndex - 1;
    if( startStateExists !== true)
    {
        throw new Error('Invalid flow def ... missing start state!');
    }
}
function buildStates ( flowInst , initObj ) { var flowInstance = flowInst ; var startStateExists = false ; flowInst . _stateBuilderIndex = flowInst . _stateBuilderStartIndex ; Object . keys ( initObj . states ) . forEach ( function ( stateName ) { var state = new State ( stateName , flowInstance . _stateBuilderIndex ) ; state . onEntry = initObj . states [ stateName ] . onEntry ; state . error = initObj . states [ stateName ] . error ; state . type = initObj . states [ stateName ] . type ; assert ( state . type , 'Invalid flow definition ... State must have type in defintion for state: ' + stateName ) ; if ( state . type === State . types . VIEW ) { state . viewName = initObj . flowDefinition . states . view [ stateName ] . viewName ; assert ( state . viewName , 'Invalid flow definition ... view state MUST have view name property: ' + stateName ) ; } assert ( state . onEntry , 'Invalid flow definition ... missing onEntry from state defintion for state: ' + stateName ) ; assert . strictEqual ( typeof state . onEntry , 'function' , 'Invalid flow def ... onEntry is not a function for state: ' + stateName ) ; assert ( state . error , 'Must have error defined for a state that is not a subflow state' ) ; Object . keys ( initObj . states [ stateName ] ) . forEach ( function ( key ) { if ( typeof key === 'string' && key !== 'onEntry' && key !== 'error' && key !== 'type' && typeof initObj . states [ stateName ] [ key ] === 'function' ) { state . userDefinedMethods [ key ] = initObj . states [ stateName ] [ key ] ; } } ) ; buildStateTransitions ( state , initObj ) ; flowInstance . endStates . forEach ( function ( endStateName ) { assert ( endStateName !== state . name , 'Existing state name and end state name are the same: ' + endStateName ) ; } ) ; flowInstance . _states [ flowInstance . _stateBuilderIndex ] = state ; flowInstance . _stateBuilderIndex += 1 ; flowInstance . _statesByName [ state . name ] = state ; if ( stateName === flowInstance . _startState ) { startStateExists = true ; } } ) ; flowInst . _stateBuilderEndIndex = flowInst . _stateBuilderIndex - 1 ; if ( startStateExists !== true ) { throw new Error ( 'Invalid flow def ... missing start state!' ) ; } }
Builds action and view states but NOT subflow states
 @param flowInst
 @param initObj
Builds action and view states but NOT subflow states @param flowInst @param initObj
// Retrieve all states and ensure there is at least a start and end // Iterate thru the state's properties to add any user defined functions to the state object // validate that state names are unique // ensure that a start state exist