Flow Redux State Machine Factory
Used to define a state machine using initializeWith and spec. It can then be started with methods like launchIn or shareIn.
Example:
init {
initializeWith { Loading }
spec {
inState<Loading> {
onEnter {
when(val result = loadData() {
is Success -> override { Content(result.data) }
is Error -> override { Error(result.errorMessage) }
}
}
}
inState<Content> {
// ...
}
inState<Error> {
on<RetryClicked> {
override { Loading }
}
}
}
}Functions
Sets the initial state for the state machine with a Parcelable state class.
Sets the initial state for the state machine.
Sets the initial state for the state machine with a state class that implements SaveableState. The implementation can save values of the state into the SavedStateHandle. The SavedStateHandle is passed to initialState on each state machine launch so that previously saved values, if present, can be used to construct the initial state.
Sets the initial state for the state machine with a kotlinx.serialization.Serializable state class.
Install a logger to observe actions in a FlowReduxStateMachine produced by this factory.
Create and start running a FlowReduxStateMachine that exposes a StateFlow. The state machine will stay active as long as the given scope is not cancelled.
Create and start running a FlowReduxStateMachine that exposes a compose State. The state machine will stay active as long as this method stays in the current composition.
Create and start running a FlowReduxStateMachine that exposes a SharedFlow. The state machine will stay active as long as the given scope is not cancelled.