node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org »

simple-machine

  .~~~~~~~~~~~~~~~.
 /  VERSION 0.1.0  \
.===================.
|                   |
|   .-----------.   |
|   |.,.,.,.,.,.|   |
|   |,.,.,.,.,.,|   |
|   |.,.,.,.,.,.|   |
|   |,.,.,.,.,.,|   |
|   '-----------'   |
|                 O |
|===================|
| ~~~~~~~~~~~~~~~~~ |
|  simple  machine  |
| ~~~~~~~~~~~~~~~~~ |
'==================='

How many lines of code you need for a finite state machine? 16... of CoffeeScript that is.

Simple Machine?

A minimal finite state machine implementation for the Node and the Browser. There is no DSLs and no bloat. Just define and trigger states.

Installation

If you are running on Node, use NPM:

npm install simple-machine

If you are running on the Browser, use this this link.

Usage

machine = new SimpleMachine 'S',
  A: {S: 'A'B: 'A'C: 'A'}
  B: {S: 'B'C: 'B'A: 'B'}
  C: {S: 'C'A: 'C'B: 'C'}
,
  A: -> console.log 'A'
  B: -> console.log 'B'
  C: -> console.log 'C'
 
machine.trigger 'A'
machine.trigger 'B'
machine.trigger 'C'

License

Simple machine is licensed under MIT.