Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Javascript version of squirrel state machine

License

NotificationsYou must be signed in to change notification settings

hekailiang/squirrel-statemachine-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

squirrel-statemachine.js is a javascript implementation ofsquirrel-foundation which is a java state machine library.

Sample Code:

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp