Skip to content

soranakk/statek

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

statek

Maven Version

Multiplatform (JVM, JS) Kotlin DSL for FSM (finite state machine)

Some samples:

stateMachine(initial = MyState.NOT_LOANED) {
   state(MyState.NOT_LOANED) {
       edge<MyEvent.PressRental>(MyState.LOCK)
   }
   state(MyState.ON_LOAN, entry = { /* LED ON */ }, exit = { /* LED OFF */ }) {
       state(MyState.LOCK) {
           edge<MyEvent.PressUnLock>(MyState.UNLOCK)
           edge<MyEvent.PressLock>(MyState.NOT_LOANED, guard = { it.isLongPress })
       }
       state(MyState.UNLOCK) {
           edge<MyEvent.PressLock>(MyState.LOCK, guard = { !it.isLongPress })
       }
   }
}

for more details, please see FsmTest

Usage with gradle:

repositories {
    maven { url "https://dl.bintray.com/tomoya0x00/maven" }
}

def statekVersion = "0.3.0"

// For multiplatform projects
implementation "com.github.tomoya0x00:statek:$statekVersion"

// For jvm projects
implementation "com.github.tomoya0x00:statek-jvm:$statekVersion"

About

Multiplatform (JVM, JS) Kotlin DSL for FSM (finite state machine)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Kotlin 100.0%