fsm-base
Finite state machine base class
Last updated 5 years ago by 75lb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fsm-base 
SYNC missed versions from official npm registry.

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI js-standard-style

fsm-base

const StateMachine = require('fsm-base')

class Stateful extends StateMachine {
  constructor () {
    super([
      { from: undefined, to: 'one' },
      { from: 'one', to: 'two' },
      { from: 'two', to: 'three' },
      { from: [ 'one', 'three' ], to: 'four'}
    ])
  }
}
const instance = new Stateful()
instance.state = 'one'  // valid state change
instance.state = 'two'  // valid state change
instance.state = 'four' // throws - invalid state change

fsm-base

StateMachine ⇐ Emitter

Kind: Exported class
Extends: Emitter

new StateMachine(initialState, validMoves)

Param Type Description
initialState string Initial state, e.g. 'pending'.
validMoves Array.<object> Array of valid move rules.

stateMachine.state : string

The current state

Kind: instance property of StateMachine
Throws:

  • INVALID_MOVE if an invalid move made

stateMachine.setState(state)

Set the current state. The second arg onward will be sent as event args.

Kind: instance method of StateMachine

Param Type
state string

stateMachine.resetState()

Reset to initial state.

Kind: instance method of StateMachine
Emits: event:"reset"

"state" (state, prev)

fired on every state change

Kind: event emitted by StateMachine

Param Type Description
state string the new state
prev string the previous state

© 2015-21 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.

Current Tags

  • 0.7.0                                ...           latest (5 years ago)

14 Versions

  • 0.7.0                                ...           5 years ago
  • 0.6.0                                ...           6 years ago
  • 0.5.2                                ...           6 years ago
  • 0.5.1                                ...           6 years ago
  • 0.5.0                                ...           6 years ago
  • 0.4.4                                ...           7 years ago
  • 0.4.3                                ...           7 years ago
  • 0.4.2                                ...           7 years ago
  • 0.4.1                                ...           7 years ago
  • 0.4.0                                ...           7 years ago
  • 0.3.0                                ...           7 years ago
  • 0.2.1                                ...           8 years ago
  • 0.2.0                                ...           9 years ago
  • 0.1.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (4)

Copyright 2013 - present © cnpmjs.org | Home |