InStateBuilderBlock

@ExperimentalCoroutinesApi
class InStateBuilderBlock<InputState : S, S : Any, A : Any> : BaseBuilderBlock<InputState, S, A>

Functions

Link copied to clipboard
fun <T> collectWhileInState(flowBuilder: (InputState) -> Flow<T>, executionPolicy: ExecutionPolicy = ExecutionPolicy.ORDERED, handler: suspend (item: T, state: State<InputState>) -> ChangedState<S>)

Triggers every time the state machine enters this state. The passed Flow created by flowBuilder will be collected and any emission will be passed to handler.

fun <T> collectWhileInState(flow: Flow<T>, executionPolicy: ExecutionPolicy = ExecutionPolicy.ORDERED, handler: suspend (item: T, state: State<InputState>) -> ChangedState<S>)

Triggers every time the state machine enters this state. The passed flow will be collected and any emission will be passed to handler.

Link copied to clipboard
fun <T> collectWhileInStateEffect(flowBuilder: (InputState) -> Flow<T>, executionPolicy: ExecutionPolicy = ExecutionPolicy.ORDERED, handler: suspend (item: T, state: InputState) -> Unit)
fun <T> collectWhileInStateEffect(flow: Flow<T>, executionPolicy: ExecutionPolicy = ExecutionPolicy.ORDERED, handler: suspend (item: T, state: InputState) -> Unit)

An effect is a way to do some work without changing the state. A typical use case is to trigger navigation as some sort of side effect or triggering analytics or do logging.

Link copied to clipboard
fun condition(condition: (InputState) -> Boolean, block: ConditionBuilderBlock<InputState, S, A>.() -> Unit)

Allows handling certain actions or events only while an extra condition is true for the current state.

Link copied to clipboard
inline fun <SubAction : A> on(executionPolicy: ExecutionPolicy = ExecutionPolicy.CANCEL_PREVIOUS, noinline handler: suspend (action: SubAction, state: State<InputState>) -> ChangedState<S>)

Triggers every time an action of type SubAction is dispatched while the state machine is in this state.

Link copied to clipboard
inline fun <SubAction : A> onActionEffect(executionPolicy: ExecutionPolicy = ExecutionPolicy.CANCEL_PREVIOUS, noinline handler: suspend (action: SubAction, stateSnapshot: InputState) -> Unit)

An effect is a way to do some work without changing the state. A typical use case would be trigger navigation as some sort of side effect or triggering analytics. This is the "effect counterpart" to handling actions that you would do with on.

Link copied to clipboard
inline fun <SubAction : A, SubStateMachineState : Any> onActionStartStateMachine(stateMachine: StateMachine<SubStateMachineState, A>, noinline stateMapper: (State<InputState>, SubStateMachineState) -> ChangedState<S>)
inline fun <SubAction : A, SubStateMachineState : Any> onActionStartStateMachine(noinline stateMachineFactory: (SubAction, InputState) -> StateMachine<SubStateMachineState, A>, noinline stateMapper: (State<InputState>, SubStateMachineState) -> ChangedState<S>)
inline fun <SubAction : A, SubStateMachineState : Any, SubStateMachineAction : Any> onActionStartStateMachine(noinline stateMachineFactory: (SubAction, InputState) -> StateMachine<SubStateMachineState, SubStateMachineAction>, noinline actionMapper: (A) -> SubStateMachineAction?, noinline stateMapper: (State<InputState>, SubStateMachineState) -> ChangedState<S>)
Link copied to clipboard
fun onEnter(handler: suspend (state: State<InputState>) -> ChangedState<S>)

Triggers every time the state machine enters this state. It only triggers again if the surrounding in<State> condition is met and will only re-trigger if in<State> condition returned false and then true again.

Link copied to clipboard
fun onEnterEffect(handler: suspend (stateSnapshot: InputState) -> Unit)

An effect is a way to do some work without changing the state. A typical use case is to trigger navigation as some sort of side effect or triggering analytics or do logging.

Link copied to clipboard
fun <SubStateMachineState : Any> onEnterStartStateMachine(stateMachine: StateMachine<SubStateMachineState, A>, stateMapper: (State<InputState>, SubStateMachineState) -> ChangedState<S> = { _, subState -> @Suppress("UNCHECKED_CAST") OverrideState(subState as S) })
fun <SubStateMachineState : Any> onEnterStartStateMachine(stateMachineFactory: (InputState) -> StateMachine<SubStateMachineState, A>, stateMapper: (State<InputState>, SubStateMachineState) -> ChangedState<S> = { _, subState -> @Suppress("UNCHECKED_CAST") OverrideState(subState as S) })
fun <SubStateMachineState : Any, SubStateMachineAction : Any> onEnterStartStateMachine(stateMachine: StateMachine<SubStateMachineState, SubStateMachineAction>, actionMapper: (A) -> SubStateMachineAction?, stateMapper: (State<InputState>, SubStateMachineState) -> ChangedState<S> = { _, subState -> @Suppress("UNCHECKED_CAST") OverrideState(subState as S) })
fun <SubStateMachineState : Any, SubStateMachineAction : Any> onEnterStartStateMachine(stateMachineFactory: (InputState) -> StateMachine<SubStateMachineState, SubStateMachineAction>, actionMapper: (A) -> SubStateMachineAction?, stateMapper: (State<InputState>, SubStateMachineState) -> ChangedState<S> = { _, subState -> @Suppress("UNCHECKED_CAST") OverrideState(subState as S) })
Link copied to clipboard

Anything inside this block will only run while the identity of the current state remains the same. The identity is determined by the given function and uses equals for the comparison.