Getting Started
# Getting Started
The Compose examples below use the 3.0.0 API. When upgrading from a published version, follow the migration guide.
Install The Right Module¶
Start with the base module:
Add the Compose module when your rendering layer is Compose Multiplatform:
For saved Repository-to-ViewModel state in commonMain, add:
kotlin {
sourceSets.commonMain.dependencies {
implementation("io.github.matheus-corregiari:event-observer-state:<version>")
}
}
Use saveState for plain values or saveResponseState for results. See the
state guide for a complete ViewModel example and serialization setup.
See the dedicated module pages for the split:
Create A Result¶
DataResult<T> is the core model. Use the helpers to build the state you need.
val loading = dataResultLoading<String>()
val success = dataResultSuccess("Loaded")
val error = dataResultError<String>(RuntimeException("Boom"))
val none = dataResultNone<String>()
Observe It In LiveData¶
ResponseLiveData<T> lets you emit DataResult values from coroutine code and observe them from
Android UI.
val userLiveData = responseLiveData<String> {
emitLoading()
emitData("Hello")
}
userLiveData.observe(this) {
loading { isLoading -> println("loading=$isLoading") }
data { value -> println(value) }
error { throwable -> println(throwable.message) }
}
Render It In Compose¶
Add event-observer-compose, then render a Flow<DataResult<T>> using Content.
For a static DataResult<T>, use Content or DataResultContent.
myFlow.Content {
OnShowLoading { CircularProgressIndicator() }
OnData { value -> Text(value.toString()) }
OnError { error -> Text(error.message ?: "Unknown error") }
}
Recommended Next Steps¶
- Read the module pages to choose the right dependency surface.
- Read Core Concepts to understand the state model.
- Use Recipes for common patterns.
- Check API Reference for per-module API docs.
- Check Changelog when you need release history.