Skip to content

killroy42/portable-fsm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

portable-fsm

Simple, node/browser compatible generic FSM system

Examples

var
	FSM = require('portable-fsm'),
	fsm = new FSM();

fsm.debug = true;

fsm.addState({
	Start: {
		init: 'InProgress'
	},
	InProgress: {
		abort: 'Cancelled',
		complete: 'Done'
	}
});

fsm
	.on('InProgress', function() {
		console.log('Progress start');
		if(Math.random() > 0.5) {
			console.log(' -> Aborting...');
			fsm.consume('abort');
		} else {
			console.log(' -> Completing...');
			fsm.consume('complete');
		}
	}, function() {
			console.log('Progress end');
	})
	.on('Cancelled', function() {
		console.log('Operation cancelled');
	})
	.on('Done', function() {
		console.log('Operation completed');
	});

fsm
	.when('complete', function() {
		console.log('ALL DONE!');
	})
	.when('abort', function() {
		console.log('ABORT! ABORT! ABORT!');
	});

fsm.consume('init');

About

Simple, node/browser compatible generic FSM system

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published