0.1.1 • Published 8 years ago
von v0.1.1
von
Finite State Machine
var fsm = require('von');
var consumption = fsm([
{ action: 'eat', from: 'hungry', to: 'satisfied'},
{ action: 'eat', from: 'satisfied', to: 'full' },
{ action: 'eat', from: 'full', to: 'sick' },
{ action: 'rest', from: ['hungry', 'satisfied', 'full', 'sick'], to: 'hungry' }
]);
var bug = consumption('hungry', {
onrest: function(action, from, to) {
console.log('Phew');
},
exithungry: function(action, from, to, food) {
console.log("I can survive, ate " + food);
},
entersick: function(action, from, to, food) {
console.log(food + " was too much!");
}
});
console.log(bug.state);
bug.eat('grass');
console.log(bug.state);
bug.eat('grass');
console.log(bug.state);
bug.eat('grass');
console.log(bug.state);
bug.rest();
0.1.1
8 years ago