KStateMachine / kstatemachine

KStateMachine is a powerful Kotlin Multiplatform library with clean DSL syntax for creating complex state machines and statecharts driven by Kotlin Coroutines.
https://kstatemachine.github.io/kstatemachine/
Boost Software License 1.0
358 stars 21 forks source link

Add the ability to receive current state #8

Closed nsk90 closed 3 years ago

nsk90 commented 3 years ago

For example if UI attaches to statemachine that is already running. UI should know its current state, to be able to draw it.

nsk90 commented 3 years ago

done https://github.com/nsk90/kstatemachine/commit/fec47507bcd6550461ee35023962992f96c0c1fc

asad-awadia commented 2 years ago

How do i get the current state from a machine object?

nsk90 commented 2 years ago

1) you can listen to per-state notifications https://github.com/nsk90/kstatemachine/blob/master/kstatemachine/src/main/kotlin/ru/nsk/kstatemachine/IState.kt#L38

2) you can listen to machine notification about all state changes https://github.com/nsk90/kstatemachine/blob/master/kstatemachine/src/main/kotlin/ru/nsk/kstatemachine/StateMachine.kt#L54

3) you can get current active states with activeStates() function. For machines with flat structure it will return single element list, for hierarchical machines there might be many active states at the same time. https://github.com/nsk90/kstatemachine/blob/master/kstatemachine/src/main/kotlin/ru/nsk/kstatemachine/IState.kt#L33

asad-awadia commented 2 years ago

thank you