2.1.2 • Published 2 months ago

easy-fsm v2.1.2

Weekly downloads
10
License
MIT
Repository
github
Last release
2 months ago

easy-fsm

An easy-to-use finite state machine system for JavaScript.

install

npm install easy-fsm

usage

import EasyFSM from 'easy-fsm'

let fsm = new EasyFSM({
  initial: 'init',
  states: {
    init: {
      on: {
        loaded: 'ready'
      }
    },
    ready: {}
  }
})

console.log(fsm.getState()) // init
await fsm.fire('loaded')
console.log(fsm.getState()) // ready

APIs

You can use new EasyFSM(options) to create a finite state machine.

  • send(event)

Send an event on current state.

  • sendAndWait(event)

Send an event on current state and wait for all listeners to finish.

  • canSend(event)

Detect if the specified event can be sent.

Get the current state.

Get the previous state.

  • onEnter(state, callback)

Execute callback when entering state.

  • onLeave(state, callback)

Execute callback when leaving state.

2.1.2

2 months ago

2.0.3

2 months ago

2.1.1

2 months ago

2.0.2

2 months ago

2.1.0

2 months ago

2.0.1

2 months ago

2.0.0

2 months ago

1.0.0

6 years ago