diff --git a/CHANGELOG.md b/CHANGELOG.md index bd074b70bd8..92b7a675688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ * `Versions`: * `Klock`: `2.4.7` -> `2.4.8` * `Serialization`: `1.3.0` -> `1.3.1` +* `FSM`: + * Now it is possible to pass any `CheckableHandlerHolder` in `FSMBuilder` + * Now `StatesMachine` works with `CheckableHandlerHolder` instead of `CustomizableHandlerHolder` ## 0.8.1 diff --git a/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/StatesMachine.kt b/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/StatesMachine.kt index f31e641a3b0..d470ff12d5c 100644 --- a/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/StatesMachine.kt +++ b/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/StatesMachine.kt @@ -12,7 +12,7 @@ import kotlinx.coroutines.* interface StatesMachine : StatesHandler { suspend fun launchStateHandling( state: T, - handlers: List> + handlers: List> ): T? { return handlers.firstOrNull { it.checkHandleable(state) } ?.run { handleState(state) @@ -35,7 +35,7 @@ interface StatesMachine : StatesHandler { */ operator fun invoke( statesManager: StatesManager, - handlers: List> + handlers: List> ) = DefaultStatesMachine(statesManager, handlers) } } @@ -46,7 +46,7 @@ interface StatesMachine : StatesHandler { */ class DefaultStatesMachine ( private val statesManager: StatesManager, - private val handlers: List> + private val handlers: List> ) : StatesMachine { /** * Will call [launchStateHandling] for state handling diff --git a/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/dsl/FSMBuilder.kt b/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/dsl/FSMBuilder.kt index 5713883f3f5..76786ecac6f 100644 --- a/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/dsl/FSMBuilder.kt +++ b/fsm/common/src/commonMain/kotlin/dev/inmo/micro_utils/fsm/common/dsl/FSMBuilder.kt @@ -9,14 +9,18 @@ class FSMBuilder( var statesManager: StatesManager = DefaultStatesManager(InMemoryDefaultStatesManagerRepo()), var defaultStateHandler: StatesHandler? = StatesHandler { null } ) { - private var states = mutableListOf>() + private var states = mutableListOf>() + + fun add(handler: CheckableHandlerHolder) { + states.add(handler) + } fun add(kClass: KClass, handler: StatesHandler) { - states.add(CheckableHandlerHolder(kClass, false, handler)) + add(CheckableHandlerHolder(kClass, false, handler)) } fun add(filter: suspend (state: State) -> Boolean, handler: StatesHandler) { - states.add(handler.holder(filter)) + add(handler.holder(filter)) } fun addStrict(kClass: KClass, handler: StatesHandler) {