Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

npm install simplejsstatemachine

Usage

Simple state machine implemented in javascript, distributable as node package.

var module = require('simplejsstatemachine');

//create state machine to represent review state.
var reviewstate = module.create('initial');

//State transition from 'initial' to 'draft' if 'publish' is triggered.
reviewstate.configure('initial').allow('publish', 'draft');

//State transition from 'draft' to 'submitted' if 'submitted' is triggered.
reviewstate.configure('draft').allow('submitted','submitted');

//register any callback that is invoked when state transition occurs.
reviewstate.on('stateChange', function(stateChange){
	console.log('Current state : ' +  stateChange.currentStateName);
	console.log('Previous state : ' +  stateChange.previousStateName);
});

//fire trigger.
reviewstate.fire('publish');

License

Licensed under MIT

About

Simple state machine implemented in javascript, distributable as node package.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages