- Notifications
You must be signed in to change notification settings - Fork3
Javascript version of squirrel state machine
License
NotificationsYou must be signed in to change notification settings
hekailiang/squirrel-statemachine-js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
squirrel-statemachine.js is a javascript implementation ofsquirrel-foundation which is a java state machine library.
varSimpleStateMachine=Squirrel.StateMachine.extend({// state machine definitionmachine :{states :{A :{onEntry:"enterA",onExit:"exitA",initial:true},B :{onEntry:"enterB",onExit:"exitB"},F :{onEntry:function(){this.callSequence+=".enterF";},onExit:function(){this.callSequence+=".exitF";},final:true}},transitions :[{from :"A",to :"B",on :"A2B",perform :"fromAToB"},{from :"B",to :"A",on :"B2A",perform :functionfromBToA(){this.callSequence+=".fromBToA";}},{from :"B",to :"C",on :"B2C",perform :functionfromCToD(){this.fire("C2D");this.fire("D2E");}},{from :"C",to :"D",on :"C2D"},{from :"D",to :"E",on :"D2E"},{from :"D",to :"F",on :"D2F",when :functionmoreThanTen(context){returncontext>10;}},{from :"A",to :"F",on :"END"}]},// state machine initialize functioninitialize :function(){this.callSequence="";},// state machine actionsenterA :function(){this.callSequence+=".enterA";},methodMissing :function(methodName){this.callSequence+="."+methodName;}});varSimpleStateMachineEx=SimpleStateMachine.extend({machine :{initial :"B",states :{A :{onEntry:"enterAFromEx:0"},// invoked after original entry methodB :{onExit:"exitBFromEx:0"}// invoked after original entry method}},enterAFromEx :function(){this.callSequence+=".enterAFromEx";},exitBFromEx :function(){this.callSequence+=".exitBFromEx";}});varsimpleStateMachineExInstance=newSimpleStateMachineEx(null/*use default*/,{isDebugInfoEnabled:true});simpleStateMachineExInstance.start();console.log("Current State: "+simpleStateMachineExInstance.getCurrentState());simpleStateMachineExInstance.fire("B2A");console.log("Call sequences: "+simpleStateMachineExInstance.callSequence);
About
Javascript version of squirrel state machine
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published