Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oldj/easy-fsm
An easy-to-use finite state machine system for JavaScript.
https://github.com/oldj/easy-fsm
Last synced: about 1 month ago
JSON representation
An easy-to-use finite state machine system for JavaScript.
- Host: GitHub
- URL: https://github.com/oldj/easy-fsm
- Owner: oldj
- License: mit
- Created: 2018-04-20T09:22:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-23T07:44:56.000Z (7 months ago)
- Last Synced: 2024-05-23T08:50:23.455Z (7 months ago)
- Language: TypeScript
- Size: 77.1 KB
- Stars: 14
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - oldj/easy-fsm - An easy-to-use finite state machine system for JavaScript. (TypeScript)
README
# easy-fsm
An easy-to-use finite state machine system for JavaScript.
## install
```bash
npm install easy-fsm
```## usage
```TypeScript
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.
- **[getter] state**
Get the current state.
- **[getter] previous_state**
Get the previous state.
- **onEnter(state, callback)**
Execute `callback` when entering `state`.
- **onLeave(state, callback)**
Execute `callback` when leaving `state`.