node package manager

PicoMachine

PicoMachine: javascript version of the ruby MicroMachine

PicoMachine

a.k.a.: MicroMachine for javascript

Description

PicoMachine is a javascript version of MicroMachine and have the same goals. To be a minimal and fully functional minimal state machine.

Usage

var PicoMachine = require('picomachine');
 
var machine = PicoMachine.new('new'); // Initial state. 
 
machine.transitionsFor['confirm'] = { new: 'confirmed' };
machine.transitionsFor['ignore']  = { new: 'ignored' };
machine.transitionsFor['reset']   = { confirmed: 'new', ignored: 'new' };
 
machine.trigger('confirm');  // true 
machine.trigger('ignore');   // false 
machine.trigger('reset');    // true 
machine.trigger('ignore');   // true