Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/batazor/fsme
Finite State Machine Engine for Go
https://github.com/batazor/fsme
finite-state-machine fsm react ui
Last synced: 9 days ago
JSON representation
Finite State Machine Engine for Go
- Host: GitHub
- URL: https://github.com/batazor/fsme
- Owner: batazor
- License: mit
- Created: 2019-01-31T13:57:46.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-17T22:42:28.000Z (about 2 months ago)
- Last Synced: 2024-09-18T03:15:02.975Z (about 2 months ago)
- Topics: finite-state-machine, fsm, react, ui
- Language: JavaScript
- Homepage: https://fsme.herokuapp.com/
- Size: 13.7 MB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Roadmap: ROADMAP.md
Awesome Lists containing this project
README
# fsme
Finite State Machine Engine for Go
[![GoDoc](https://godoc.org/github.com/ryanfaerman/fsm?status.png)](https://godoc.org/github.com/batazor/fsme/fsm)
### Try it
1. [Demo](https://fsme.herokuapp.com/)
-----
-----
### Install
`go get github.com/batazor/fsme/fsm`
### Basic Example
From [examples/simple.go](./examples/simple.go)
```go
package mainimport (
"fmt"
"github.com/batazor/fsme/fsm"
)func main() {
// Create new FSM
machine, err := fsm.New()// Add rule
machine.AddStateTransitionRules("a", "b", "c")
machine.AddStateTransitionRules("b", "d", "e")
machine.AddStateTransitionRules("c", "k")
machine.AddStateTransitionRules("d", "a")
machine.AddStateTransitionRules("e", "k")
machine.AddStateTransitionRules("k")// Add Events
machine.AddEvent("start", "a")
machine.AddEvent("to b", "b")
machine.AddEvent("to d", "d")// Add callback for state
machine.AddCallback("a", "enter", func(f *fsm.FSM) { fmt.Println("Enter state: ", f.GetCurrentState()) })
machine.AddCallback("a", "leave", func(f *fsm.FSM) { fmt.Println("Leave state: ", f.GetCurrentState()) })
machine.AddCallback("b", "enter", func(f *fsm.FSM) { fmt.Println("Enter state: ", f.GetCurrentState()) })// Init State
err = machine.SetStateTransition("a")
if err != nil {
fmt.Println(err)
}// Send Event
err = machine.SendEvent("to b")
if err != nil {
fmt.Println(err)
}
err = machine.SendEvent("to d")
if err != nil {
fmt.Println(err)
}fmt.Printf("State: %s\n", machine.GetCurrentState())
}
```## UI
![view](./docs/editor.png)
![view-editor](./docs/view-editor.png)### Feature
+ FSM
+ Callback [Entry, Leave]
+ UI Editor/View
+ Export
+ [Examples](./examples)### Refs
- FSM
- https://github.com/looplab/fsm
- https://github.com/theckman/go-fsm