
Manages remote data state with sealed Loading/Success/Error model, reactive flows, type-safe transitions, mapping utilities (mapSuccess/mapError), atomic success updates and zero-dependency implementation.
A Kotlin Multiplatform library for managing remote state in your Android, iOS, and Web applications.
Moko State provides a simple and efficient way to handle remote data states with Kotlin's coroutines and Flow. It's designed for multiplatform projects, allowing you to share state management logic across iOS, Android, and Web platforms.
Add the dependency to your common source set:
implementation("dev.icerock.moko:state:[latestVersion]")import dev.icerock.moko.state.RemoteState
import dev.icerock.moko.state.mapSuccess
// Define your state
val stateFlow = MutableStateFlow<RemoteState<String, Exception>>(
value = RemoteState.Loading
)
// Update state
stateFlow.value = RemoteState.Success("Hello, World!")
// Map success value
val mappedState = stateFlow.value.mapSuccess { it.uppercase() }
// Check state
if (mappedState.isSuccess()) {
println(mappedState.data)
}A sealed class representing the state of remote data.
Loading - Represents an ongoing operationSuccess<T> - Contains successfully loaded dataError<E> - Contains an error occurred during operationmapSuccess - Transform data in Success statemapError - Transform error in Error stateisLoading - Check if state is loadingisSuccess - Check if state is successfultryUpdateSuccess - Atomically update data in Success stateAll development (both new features and bug fixes) is performed in the develop branch. This way master always contains the sources of the most recently released version. Please send PRs with bug fixes to the develop branch. Documentation fixes in the markdown files are an exception to this rule. They are updated directly in master.
The develop branch is pushed to master on release.
For more details on contributing please see the contributing guide.
Apache 2.0 License - see LICENSE file for details.
A Kotlin Multiplatform library for managing remote state in your Android, iOS, and Web applications.
Moko State provides a simple and efficient way to handle remote data states with Kotlin's coroutines and Flow. It's designed for multiplatform projects, allowing you to share state management logic across iOS, Android, and Web platforms.
Add the dependency to your common source set:
implementation("dev.icerock.moko:state:[latestVersion]")import dev.icerock.moko.state.RemoteState
import dev.icerock.moko.state.mapSuccess
// Define your state
val stateFlow = MutableStateFlow<RemoteState<String, Exception>>(
value = RemoteState.Loading
)
// Update state
stateFlow.value = RemoteState.Success("Hello, World!")
// Map success value
val mappedState = stateFlow.value.mapSuccess { it.uppercase() }
// Check state
if (mappedState.isSuccess()) {
println(mappedState.data)
}A sealed class representing the state of remote data.
Loading - Represents an ongoing operationSuccess<T> - Contains successfully loaded dataError<E> - Contains an error occurred during operationmapSuccess - Transform data in Success statemapError - Transform error in Error stateisLoading - Check if state is loadingisSuccess - Check if state is successfultryUpdateSuccess - Atomically update data in Success stateAll development (both new features and bug fixes) is performed in the develop branch. This way master always contains the sources of the most recently released version. Please send PRs with bug fixes to the develop branch. Documentation fixes in the markdown files are an exception to this rule. They are updated directly in master.
The develop branch is pushed to master on release.
For more details on contributing please see the contributing guide.
Apache 2.0 License - see LICENSE file for details.