Package-level declarations

Types

Link copied to clipboard
open class BaseStateImpl(val name: String?, val childMode: ChildMode) : InternalState

Base IState implementation for all states

Link copied to clipboard
Link copied to clipboard

State which holds data while it is active

Link copied to clipboard

Same as TransitionStateApi interface, for specialized DataState api.

Link copied to clipboard
open class DefaultDataState<D : Any>(val name: String? = null, val defaultData: D? = null, val childMode: ChildMode = EXCLUSIVE, dataExtractor: DataExtractor<D>) : BaseStateImpl, DataState<D>
Link copied to clipboard
open class DefaultFinalDataState<D : Any>(name: String? = null, defaultData: D? = null, dataExtractor: DataExtractor<D>) : DefaultDataState<D> , FinalDataState<D>
Link copied to clipboard
open class DefaultFinalState(val name: String? = null) : DefaultState, FinalState
Link copied to clipboard
open class DefaultState(val name: String? = null, val childMode: ChildMode = EXCLUSIVE) : BaseStateImpl, State

The most common state

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
interface GroupListener
Link copied to clipboard

Pseudo-state that represents the child state that the parent state was in the last time before exited.

Link copied to clipboard
Link copied to clipboard
interface IFinalState : IState

Marker interface. When StateMachine enters this state it finishes and does not accept events anymore. It is possible to use this interface to mark final state directly instead of subclassing DefaultFinalState

Link copied to clipboard
abstract class InternalState : IState, InternalNode

Defines state API for internal library usage. All states must implement this class. Unfortunately cannot use interface for this purpose. This is safe to cast any IState to InternalState by design for internal library implementation.

Link copied to clipboard

Base interface for all kind of states. Many additional methods implemented like extensions to keep this interface clean and minimalistic. States are mutable subject by the library design.

Link copied to clipboard
interface PseudoState : State

Pseudo state is a state that machine passes automatically without explicit event. It cannot be active.

Link copied to clipboard
Link copied to clipboard
interface State : IState

Simple state in most cases equal to IState. Using this interface explicitly says that the state does not have a data field that is used by typesafe transitions. Helps to break compilation if a user specifies DataState as a target of non-data transition.

Link copied to clipboard
typealias StateBlock<S> = suspend S.() -> Unit
Link copied to clipboard

Helper interface for IState to keep transitions logic separately.

Functions

Link copied to clipboard
fun IState.activeStates(selfIncluding: Boolean = false): Set<IState>

Set of states that the state is currently in. Including state itself if selfIncluding is true. Internal states of nested machines are not included.

Link copied to clipboard
suspend fun <S : IFinalState> IState.addFinalState(state: S, init: StateBlock<S>? = null): S

Helper dsl method for adding final states. This is exactly the same as simply call IState.addState but makes code more self expressive.

Link copied to clipboard
suspend fun <S : IState> IState.addInitialState(state: S, init: StateBlock<S>? = null): S

A shortcut for IState.addState and IState.setInitialState calls

Link copied to clipboard
suspend fun <S : IState> IState.addState(state: S, init: StateBlock<S>? = null): S
Link copied to clipboard
inline fun <D : Any> IState.choiceDataState(name: String? = null, noinline choiceAction: suspend EventAndArgument<*>.() -> DataState<D>): DefaultChoiceDataState<D>
Link copied to clipboard
fun IState.choiceState(name: String? = null, choiceAction: suspend EventAndArgument<*>.() -> State): DefaultChoiceState
Link copied to clipboard
inline suspend fun <D : Any> IState.dataState(name: String? = null, defaultData: D? = null, childMode: ChildMode = ChildMode.EXCLUSIVE, dataExtractor: DataExtractor<D> = defaultDataExtractor(), noinline init: StateBlock<DataState<D>>? = null): DefaultDataState<D>
Link copied to clipboard

Creates type safe argument transition to DataState.

inline fun <E : DataEvent<D>, D : Any> DataTransitionStateApi<D>.dataTransition(name: String? = null, type: TransitionType = LOCAL, metaInfo: MetaInfo? = null): Transition<E>

Shortcut function for type safe target-less (self targeted) transition.

inline fun <E : DataEvent<D>, D : Any> TransitionStateApi.dataTransition(name: String? = null, targetState: DataState<D>, type: TransitionType = LOCAL, metaInfo: MetaInfo? = null): Transition<E>

Shortcut function for type safe argument transition. Data transition can be target-less (self-targeted), it is useful to update DataState data Note that transition must be TransitionType.EXTERNAL to update data.

Link copied to clipboard

Data transition, otherwise same as transitionOn

Link copied to clipboard
inline fun <D : Any> defaultDataState(name: String? = null, defaultData: D? = null, childMode: ChildMode = EXCLUSIVE, dataExtractor: DataExtractor<D> = defaultDataExtractor()): DefaultDataState<D>

inline constructor function

Link copied to clipboard
inline fun <D : Any> defaultFinalDataState(name: String? = null, defaultData: D? = null, dataExtractor: DataExtractor<D> = defaultDataExtractor()): DefaultFinalDataState<D>

inline constructor function

Link copied to clipboard
inline suspend fun <D : Any> IState.finalDataState(name: String? = null, defaultData: D? = null, dataExtractor: DataExtractor<D> = defaultDataExtractor(), noinline init: StateBlock<FinalDataState<D>>? = null): DefaultFinalDataState<D>
Link copied to clipboard
suspend fun IState.finalState(name: String? = null, init: StateBlock<FinalState>? = null): DefaultFinalState
Link copied to clipboard
inline fun <S : IState> IState.findState(recursive: Boolean = true): S?

Find state by type. Search by type is suitable when using own state subclasses that usually do not have a name. Only on state should match the type or exception will be thrown.

fun IState.findState(name: String, recursive: Boolean = true): IState?

Get state by name. This might be used to start listening to state after state machine setup.

fun <S : IState> IState.findState(class: KClass<S>, recursive: Boolean = true): S?

For internal use. Workaround that Kotlin does not support recursive inline functions.

Link copied to clipboard

Find transition by Event type. This might be used to start listening to transition after state machine setup.

Find transition by name. This might be used to start listening to transition after state machine setup.

Link copied to clipboard
fun IState.historyState(name: String? = null, defaultState: IState? = null, historyType: HistoryType = HistoryType.SHALLOW): DefaultHistoryState
Link copied to clipboard
inline suspend fun <D : Any> IState.initialChoiceDataState(name: String? = null, noinline choiceAction: suspend EventAndArgument<*>.() -> DataState<D>): DefaultChoiceDataState<D>
Link copied to clipboard
suspend fun IState.initialChoiceState(name: String? = null, choiceAction: suspend EventAndArgument<*>.() -> State): DefaultChoiceState
Link copied to clipboard
inline suspend fun <D : Any> IState.initialDataState(name: String? = null, defaultData: D, childMode: ChildMode = ChildMode.EXCLUSIVE, dataExtractor: DataExtractor<D> = defaultDataExtractor(), noinline init: StateBlock<DataState<D>>? = null): DefaultDataState<D>
Link copied to clipboard
inline suspend fun <D : Any> IState.initialFinalDataState(name: String? = null, defaultData: D? = null, dataExtractor: DataExtractor<D> = defaultDataExtractor(), noinline init: StateBlock<FinalDataState<D>>? = null): DefaultFinalDataState<D>
Link copied to clipboard
suspend fun IState.initialFinalState(name: String? = null, init: StateBlock<FinalState>? = null): DefaultFinalState
Link copied to clipboard
suspend fun IState.initialState(name: String? = null, childMode: ChildMode = ChildMode.EXCLUSIVE, init: StateBlock<State>? = null): DefaultState

A shortcut for state and IState.setInitialState calls

Link copied to clipboard
suspend operator fun <S : IState> S.invoke(block: StateBlock<S>)
Link copied to clipboard
suspend fun IState.log(lazyMessage: () -> String)
Link copied to clipboard
Link copied to clipboard
inline fun <E : Event> matcherForEvent(state: IState): EventMatcher<E>
Link copied to clipboard
fun onActiveAllOf(states: Set<IState>, notifyOnSubscribe: Boolean = false, onChanged: (Boolean) -> Unit): GroupListener

fun onActiveAllOf(mandatoryState1: IState, mandatoryState2: IState, vararg otherStates: IState, notifyOnSubscribe: Boolean = false, onChanged: (Boolean) -> Unit): GroupListener

Triggers onChanged callback when condition "all passed states are active" changes

Link copied to clipboard
fun onActiveAnyOf(states: Set<IState>, notifyOnSubscribe: Boolean = false, onChanged: (Boolean) -> Unit): GroupListener

fun onActiveAnyOf(mandatoryState1: IState, mandatoryState2: IState, vararg otherStates: IState, notifyOnSubscribe: Boolean = false, onChanged: (Boolean) -> Unit): GroupListener

Triggers onChanged callback when condition "any of passed states is active" changes

Link copied to clipboard
inline fun <S : IState> S.onEntry(once: Boolean = false, crossinline block: suspend S.(TransitionParams<*>) -> Unit): IState.Listener

The most commonly used methods onEntry and onExit are shipped with once argument, to remove listener after it is triggered the first time. Looks that it is not necessary in other similar methods.

Link copied to clipboard
inline fun <S : IState> S.onExit(once: Boolean = false, crossinline block: suspend S.(TransitionParams<*>) -> Unit): IState.Listener
Link copied to clipboard
inline fun <S : IState> S.onFinished(crossinline block: suspend S.(TransitionParams<*>) -> Unit): IState.Listener
Link copied to clipboard
Link copied to clipboard
inline fun <S : IState> IState.requireState(recursive: Boolean = true): S

Require state by type

fun IState.requireState(name: String, recursive: Boolean = true): IState
Link copied to clipboard

Require transition by Event type

Link copied to clipboard
suspend fun IState.state(name: String? = null, childMode: ChildMode = ChildMode.EXCLUSIVE, init: StateBlock<State>? = null): DefaultState
Link copied to clipboard
inline fun <E : Event> TransitionStateApi.transition(name: String? = null, block: UnitGuardedTransitionBuilder<E>.() -> Unit): Transition<E>

Creates transition. You can specify guard function. Such guarded transition is triggered only when guard function returns true.

inline fun <E : Event> TransitionStateApi.transition(name: String? = null, targetState: State? = null, type: TransitionType = LOCAL, metaInfo: MetaInfo? = null): Transition<E>

Shortcut overload for transition with an optional target state

Link copied to clipboard

Creates conditional transition. Caller should specify lambda which calculates TransitionDirection. For example target state may be different depending on some condition.

Link copied to clipboard

This is more powerful version of transition function. Here target state is a lambda which returns desired State. This allows to use lateinit state variables for recursively depending states and choose target state depending on application business logic.