0.0.6 • Published 6 years ago

state-transition v0.0.6

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

state-transition

Simple state machine library.

npm install state-transition

Usage

First argument to the constructor is the initial state followed by the state transitions.

var StateMachine = require('state-transition')

var sm = new StateMachine('idle', {
  start: [
    { from: 'idle', to: 'analyzing' }
  ],
  stop: [
    { from: 'analyzing', to: 'advisory', condition: () => some_condition }
  ],
  cancel: [
    { from: ['analyzing', 'advisory'], to: 'idle' }
  ],
  advisory: [
    { from: '*', to: 'advisory' }
  ]
})

sm.onEnter('analyzing', function () {
  console.log('analyzing started')
})

sm.onLeave('analyzing', function () {
  console.log('analyzing finished')
})

sm.onError(function (err) {
  console.error('error', err)
})

sm.trigger('start')
0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago