examples/ShoppingCartMachine.js
/**
 * In this example, a new operation and transition are added to the machine: removeItemOperation, and a transition
 * that now includes a transition with a dynamic final state that based on a property of the machine (item) determines
 * if its final state is PRICEABLE or NON_PRICEABLE. Essentially, if there's no items, final state must be NON_PRICEABLE
 * , on the other hand, if there are 1 or more items, final state of transition must be PRICEABLE.
 * @returns {*}
 * @constructor
 */
In this example, a new operation and transition are added to the machine: removeItemOperation, and a transition
that now includes a transition with a dynamic final state that based on a property of the machine (item) determines
if its final state is PRICEABLE or NON_PRICEABLE. Essentially, if there's no items, final state must be NON_PRICEABLE
, on the other hand, if there are 1 or more items, final state of transition must be PRICEABLE.
@returns {*}
@constructor
In this example a new operation and transition are added to the machine : removeItemOperation and a transition that now includes a transition with a dynamic final state that based on a property of the machine ( item ) determines if its final state is PRICEABLE or NON_PRICEABLE . Essentially if there ' s no items final state must be NON_PRICEABLE on the other hand if there are 1 or more items final state of transition must be PRICEABLE . @returns { * } @constructor
function ShoppingCartMachineWithMutableStates() {
    var machine = new ShoppingCartMachineWithComplexValues();
    var removeItemOperation = new Operation("removeItem", function (machine, parameters, transition, cb) {
        var err = null;
        machine.getProperties()["items"].getValue().pop();
        if (!err) {
            cb(null, machine.setCurrentState(transition.getFinalState(machine)));
        } else {
            cb(err, null);
        }
    });
    var removeItemInitialState = function(machine){
        if(machine.getProperties()["items"].getValue().length == 0) return "NON_PRICEABLE";
        return "PRICEABLE";
    };
    var removeItemFinalState = function(machine){
      if(machine.getProperties()["items"].getValue().length == 0) return "NON_PRICEABLE";
      return "PRICEABLE";
    };
    machine._transitions.push(new Transition(removeItemInitialState, removeItemFinalState, removeItemOperation));
    return machine;
}
function ShoppingCartMachineWithMutableStates ( ) { var machine = new ShoppingCartMachineWithComplexValues ( ) ; var removeItemOperation = new Operation ( "removeItem" , function ( machine , parameters , transition , cb ) { var err = null ; machine . getProperties ( ) [ "items" ] . getValue ( ) . pop ( ) ; if ( ! err ) { cb ( null , machine . setCurrentState ( transition . getFinalState ( machine ) ) ) ; } else { cb ( err , null ) ; } } ) ; var removeItemInitialState = function ( machine ) { if ( machine . getProperties ( ) [ "items" ] . getValue ( ) . length == 0 ) return "NON_PRICEABLE" ; return "PRICEABLE" ; } ; var removeItemFinalState = function ( machine ) { if ( machine . getProperties ( ) [ "items" ] . getValue ( ) . length == 0 ) return "NON_PRICEABLE" ; return "PRICEABLE" ; } ; machine . _transitions . push ( new Transition ( removeItemInitialState , removeItemFinalState , removeItemOperation ) ) ; return machine ; }
In this example, a new operation and transition are added to the machine: removeItemOperation, and a transition
 that now includes a transition with a dynamic final state that based on a property of the machine (item) determines
 if its final state is PRICEABLE or NON_PRICEABLE.
In this example a new operation and transition are added to the machine : removeItemOperation and a transition that now includes a transition with a dynamic final state that based on a property of the machine ( item ) determines if its final state is PRICEABLE or NON_PRICEABLE .