initializeWith

fun <S : Parcelable> FlowReduxStateMachineFactory<S, *>.initializeWith(savedStateHandle: SavedStateHandle, initialState: () -> S)

Sets the initial state for the state machine with a Parcelable state class.

The first time a state machine is launched from this FlowReduxStateMachineFactory instance, initialState is called to produce the initial state. Any emitted state from a state machine will be saved to the savedStateHandle and subsequent launches will read the state from there instead of calling initialState.

fun <S : Any> FlowReduxStateMachineFactory<S, *>.initializeWith(reuseLastEmittedStateOnLaunch: Boolean = true, initialState: () -> S)

Sets the initial state for the state machine.

When reuseLastEmittedStateOnLaunch is true initialState will only be called the first time a state machine is launched. Subsequent launches will start using the last emitted value by a launched state machine. When the multiple state machines from the same factory instance are launched in parallel the state of whichever state machine emitted last will be used.

reuseLastEmittedStateOnLaunch being false will result in initialState being called for every launch.

fun <S : SaveableState> FlowReduxStateMachineFactory<S, *>.initializeWith(savedStateHandle: SavedStateHandle, initialState: (SavedStateHandle) -> S)

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.


inline fun <S : Any> FlowReduxStateMachineFactory<S, *>.initializeWith(savedStateHandle: SavedStateHandle, noinline initialState: () -> S)

Sets the initial state for the state machine with a kotlinx.serialization.Serializable state class.

The first time a state machine is launched from this FlowReduxStateMachineFactory instance, initialState is called to produce the initial state. Any emitted state from a state machine will be saved to the savedStateHandle and subsequent launches will read the state from there instead of calling initialState.