All Projects → nsk90 → kstatemachine

nsk90 / kstatemachine

Licence: BSL-1.0 license
KStateMachine is a Kotlin DSL library for creating finite state machines (FSM) and hierarchical state machines (HSM).

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to kstatemachine

xstate-cpp-generator
C++ State Machine generator for Xstate
Stars: ✭ 33 (-47.62%)
Mutual labels:  state-management, fsm, state-machine, fsm-library
qm
QM model-based design tool and code generator based on UML state machines
Stars: ✭ 54 (-14.29%)
Mutual labels:  fsm, state-machine, hierarchical-state-machine
fea state machines
A Buffet Of C++17 State Machines
Stars: ✭ 19 (-69.84%)
Mutual labels:  fsm, state-machine, fsm-library
Transitions
A lightweight, object-oriented finite state machine implementation in Python with many extensions
Stars: ✭ 4,082 (+6379.37%)
Mutual labels:  state-machine, nested-states, hierarchical-state-machine
xstate
State machines and statecharts for the modern web.
Stars: ✭ 21,286 (+33687.3%)
Mutual labels:  state-management, fsm, state-machine
use-state-machine
Use Finite State Machines with React Hooks
Stars: ✭ 28 (-55.56%)
Mutual labels:  state-management, fsm, state-machine
tsm
A Hierarchical State Machine Framework in C++
Stars: ✭ 30 (-52.38%)
Mutual labels:  state-machine, hsm, hierarchical-state-machine
bloc
A predictable state management library that helps implement the BLoC design pattern
Stars: ✭ 12 (-80.95%)
Mutual labels:  state-management, state-machine
kuafu
This is a tool library that includes log, fsm, state machine...
Stars: ✭ 83 (+31.75%)
Mutual labels:  fsm, state-machine
hsm
C++ framework library to simplify state-driven code
Stars: ✭ 88 (+39.68%)
Mutual labels:  state-machine, hsm
stateless
Finite State Machine porting from Stateless C#
Stars: ✭ 25 (-60.32%)
Mutual labels:  fsm, state-machine
xoid
Framework-agnostic state management library designed for simplicity and scalability ⚛
Stars: ✭ 96 (+52.38%)
Mutual labels:  state-management, state-machine
Xstate
State machines and statecharts for the modern web.
Stars: ✭ 18,300 (+28947.62%)
Mutual labels:  state-management, state-machine
pastafarian
A tiny event-based finite state machine
Stars: ✭ 20 (-68.25%)
Mutual labels:  fsm, state-machine
Use Machine
React Hook for using Statecharts powered by XState. use-machine.
Stars: ✭ 226 (+258.73%)
Mutual labels:  state-management, state-machine
asyncmachine
Relational State Machine with a visual inspector
Stars: ✭ 67 (+6.35%)
Mutual labels:  state-management, state-machine
State Machine Component
⚙️ State machine -powered components in 250 bytes
Stars: ✭ 178 (+182.54%)
Mutual labels:  state-management, state-machine
flow
A Statically Type Checked State Machine DSL for Kotlin
Stars: ✭ 74 (+17.46%)
Mutual labels:  fsm, state-machine
remachine
[WIP] Reason pattern matching viz
Stars: ✭ 44 (-30.16%)
Mutual labels:  fsm, state-machine
qp-arduino
QP real-time embedded frameworks/RTOS for Arduino (AVR and SAM)
Stars: ✭ 37 (-41.27%)
Mutual labels:  fsm, state-machine

KStateMachine

Build and test with Gradle Quality Gate Status Dependencies none codecov Android Arsenal

KStateMachine is a Kotlin DSL library for creating finite state machines (FSM) and hierarchical state machines (HSM).

Overview

Main features are:

  • Zero dependency. It is written in pure Kotlin, it does not depend on any other libraries or Android SDK
  • Kotlin DSL syntax for defining state machine structure. Using without DSL is also possible
  • Event based - transitions are performed by processing incoming events
  • Listeners for machine, states and transitions, all callbacks are shipped with information about current transition
  • Guarded and Conditional transitions with dynamic target state which is calculated in a moment of event processing depending on application business logic
  • Nested states - hierarchical state machines (HSMs) with cross level transitions support
  • Composed (nested) state machines. Use state machines as atomic child states
  • Typesafe transitions to pass data in typesafe way from event to state
  • Parallel states to avoid a combinatorial explosion of states
  • Argument passing for events and transitions
  • Export state machine structure to PlantUML;
  • Built-in logging support

The library is currently in a development phase. You are welcome to propose useful features.

SEE WIKI PAGE FOR MORE INFO

Quick start sample (finishing traffic light)

Traffic light diagram

sealed class Events {
    object NextEvent : Event
}

sealed class States {
    object GreenState : DefaultState()
    object YellowState : DefaultState()
    object RedState : DefaultFinalState() // Machine finishes when enters final state
}

fun main() {
    // Create state machine and configure its states in a setup block
    val machine = createStateMachine {
        addInitialState(GreenState) {
            // Add state listeners
            onEntry { println("Enter green") }
            onExit { println("Exit green") }

            // Setup transition
            transition<NextEvent> {
                targetState = YellowState
                // Add transition listener
                onTriggered { println("Transition triggered") }
            }
        }

        addState(YellowState) {
            transition<NextEvent>(targetState = RedState)
        }

        addFinalState(RedState)

        onFinished { println("Finished") }
    }

    // Now we can process events
    machine.processEvent(NextEvent)
    machine.processEvent(NextEvent)
}

Samples

Install

KStateMachine is available on Maven Central and JitPack repositories.

Maven Central

Add the dependency:

dependencies {
    implementation 'io.github.nsk90:kstatemachine:<Tag>'
}

Where <Tag> is a library version.

JitPack

Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        //  ...
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency:

dependencies {
    implementation 'com.github.nsk90:kstatemachine:<Tag>'
}

Where <Tag> is a library version.

Build

Run ./gradlew build or build with Intellij IDEA.

To run tests from IDE download official Kotest plugin.

Licensed under the Boost Software License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].