var{FSM, State}=require("dropecho.fsm");varentity={data: 0};// input function is state "action", called when state is run.vartestState1=newState(entity=>{entity.data+=1;console.log("state1");});vartestState2=newState(entity=>{entity.state2Ran=true;console.log("state2");})testState1.transitions.push(entity=>{if(entity.data>=2){returntestState2;}// null means don't transitionreturnnull;});st2.transitions.push(entity->{if(entity.state2Ran){returnst1;}returnnull;});varfsm=newFSM(testState1);fsm.run();// state1fsm.run();// state1fsm.run();// state2fsm.run();// state1fsm.run();// state2fsm.run();// state1fsm.run();// state2