@wiz-code/async-fsm
Version:
Finite StateMachine JavaScript Library
55 lines (44 loc) • 1.36 kB
JavaScript
var _ = require('underscore');
var FSM = require('../src');
//FSM.logger.disable();
var m = new FSM.Machine('my-machine');
var s1 = new FSM.State('s1', {
entryAction: function () {
console.log('entryAction::', this.getName());
},
doActivity: function () {
console.log('doActivity::', this.getName());
s1ToChoice.set({
choice: 's3',
});
s1ToChoice.trigger();
},
});
var choice = new FSM.ChoicePseudoState('choice', function (transit) {
var target = transit.get('choice') === 's2' ? s2 : s3;
return target;
});
var s2 = new FSM.State('s2', {
entryAction: function () {
console.log('entryAction::', this.getName());
},
doActivity: function () {
console.log('doActivity::', this.getName());
},
});
var s3 = new FSM.State('s3', {
entryAction: function () {
console.log('entryAction::', this.getName());
},
doActivity: function () {
console.log('doActivity::', this.getName());
},
});
m.addState(s1, s2, s3, choice);
var t1 = new FSM.Transition(false, false, s1);
var s1ToChoice = new FSM.Transition(false, s1, choice);
var choiceToS2 = new FSM.Transition(false, choice, s2);
var choiceToS3 = new FSM.Transition(false, choice, s3);
m.addTransition(t1, s1ToChoice, choiceToS2, choiceToS3);
m.deploy();
m.start();