Skip to content
/ fsmjs Public

JavaScript Finite State Machine with streams

License

Notifications You must be signed in to change notification settings

roobie/fsmjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fsmjs

JavaScript Finite State Machine with streams

inspired by https://github.com/jakesgordon/javascript-state-machine

var logger = function (arg) {
  return function () {
    log(arg);
  }
}
var machine = fsm({
  initialState: 'green',
  transitions: {
    clear: { from: '*', to: 'green' },
    warn: { from: 'green', to: 'yellow' },
    alert: { from: ['green', 'yellow'], to: 'red' },
  }
});
machine.warn();

machine.onbeforeclear(logger('1. before clear'));
machine.onexityellow(logger('2. exited yellow'));
machine.onentergreen(logger('3. entered green'));
machine.ongreen(logger('4. green'));
machine.onclear(logger('5. clear'));
machine.onafterclear(logger('6. after clear'));

machine.clear();

About

JavaScript Finite State Machine with streams

Resources

License

Stars

Watchers

Forks

Packages

No packages published