
Event and result observation with DataResult, LiveData/Flow wrappers, chaining/mapping/merge helpers and a Compose-first DSL for declarative loading, data, error and collection handling.
Kotlin-first event and result observation for Android and Compose Multiplatform.
The project is split into three public modules:
event-observer for DataResult, ResponseLiveData, ResponseFlow, and the supporting
utilitiesevent-observer-compose for ComposableDataResult and the Compose-facing observation DSLevent-observer-state for serializable SavedStateHandle state, repository operations and projections2.4.10
9.7.1
21 via the Gradle toolchainminSdk 23 and compileSdk 37
1.12.0 with iOS ARM targetsThe library centers on DataResult<T> and a small set of wrappers that keep loading, success,
error, and list-state handling consistent across Android and Compose layers.
Use event-observer when you want:
DataResult helpers and status handlingResponseLiveData, MutableResponseLiveData, and SwapResponseLiveData
ResponseFlow, ResponseStateFlow, and ResponseSharedFlow
Use event-observer-compose when you want:
ComposableDataResult for declarative state renderingcollectAsComposableState() for Flow<DataResult<T>> and LiveData<DataResult<T>>
OnData, OnError, OnShowLoading, OnEmpty, OnNotEmpty,
OnSingle, and OnMany
event-observer
Use event-observer-state when you want:
SavedStateHandle
DataResult
Pick the module that matches your layer:
dependencies {
implementation("io.github.matheus-corregiari:event-observer:<version>")
}dependencies {
implementation("io.github.matheus-corregiari:event-observer-compose:<version>")
}event-observer-compose builds on top of event-observer, so use both only when you need
Compose rendering on top of the base result model.
For saved state in shared code:
kotlin {
sourceSets.commonMain.dependencies {
implementation("io.github.matheus-corregiari:event-observer-state:<version>")
}
}Apply the Kotlin serialization plugin in the module declaring your @Serializable models.
The state artifact includes the base result API; add the Compose artifact for its rendering DSL.
event-observer
event-observer-compose
ComposableDataResultUse only event-observer when your UI layer is not Compose. Add event-observer-compose when the
final observation point lives inside Jetpack Compose Multiplatform.
The fastest path is to start with DataResult and render it where you need it.
val result = dataResultSuccess("Hello")
result.unwrap {
data { value -> println(value) }
error { throwable -> println(throwable.message) }
loading { isLoading -> println("loading=$isLoading") }
}For Compose, convert the upstream state into a ComposableDataResult and render the blocks you care
about.
myFlow.composable
.OnShowLoading { CircularProgressIndicator() }
.OnData { value -> Text(value.toString()) }
.OnError { error -> Text(error.message ?: "Unknown error") }
.Unwrap()For saved state, declare a shared ViewModel and start a new operation on refresh:
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import br.com.arch.toolkit.eventObserver.state.saveResponseState
import br.com.arch.toolkit.result.DataResult
import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.Serializable
@Serializable
data class User(val name: String)
class UsersViewModel(handle: SavedStateHandle) : ViewModel() {
val users by handle.saveResponseState<List<User>>()
val count = users.select { it?.size ?: 0 }
fun refresh(source: () -> Flow<DataResult<List<User>>>) = users.load { source() }
}Observe users.flow() from the View. Its last payload survives completed requests and is restored
through the handle's owner. See the state guide for filters,
plain values, mapping and platform restoration limits.
Public docs live in docs/:
The published MkDocs site is built from the same content and mirrors these pages.
event-observer is Android-facing and integrates with LiveData.event-observer-compose builds on top of event-observer, Flow, and Compose state.Read CONTRIBUTING.md before sending changes.
Copyright 2025 Matheus Corregiari
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
See event-observer-state for one-shot requests, refresh, filters, continuous streams and transformations. Existing Toolkit consumers should follow the migration guide.
Kotlin-first event and result observation for Android and Compose Multiplatform.
The project is split into three public modules:
event-observer for DataResult, ResponseLiveData, ResponseFlow, and the supporting
utilitiesevent-observer-compose for ComposableDataResult and the Compose-facing observation DSLevent-observer-state for serializable SavedStateHandle state, repository operations and projections2.4.10
9.7.1
21 via the Gradle toolchainminSdk 23 and compileSdk 37
1.12.0 with iOS ARM targetsThe library centers on DataResult<T> and a small set of wrappers that keep loading, success,
error, and list-state handling consistent across Android and Compose layers.
Use event-observer when you want:
DataResult helpers and status handlingResponseLiveData, MutableResponseLiveData, and SwapResponseLiveData
ResponseFlow, ResponseStateFlow, and ResponseSharedFlow
Use event-observer-compose when you want:
ComposableDataResult for declarative state renderingcollectAsComposableState() for Flow<DataResult<T>> and LiveData<DataResult<T>>
OnData, OnError, OnShowLoading, OnEmpty, OnNotEmpty,
OnSingle, and OnMany
event-observer
Use event-observer-state when you want:
SavedStateHandle
DataResult
Pick the module that matches your layer:
dependencies {
implementation("io.github.matheus-corregiari:event-observer:<version>")
}dependencies {
implementation("io.github.matheus-corregiari:event-observer-compose:<version>")
}event-observer-compose builds on top of event-observer, so use both only when you need
Compose rendering on top of the base result model.
For saved state in shared code:
kotlin {
sourceSets.commonMain.dependencies {
implementation("io.github.matheus-corregiari:event-observer-state:<version>")
}
}Apply the Kotlin serialization plugin in the module declaring your @Serializable models.
The state artifact includes the base result API; add the Compose artifact for its rendering DSL.
event-observer
event-observer-compose
ComposableDataResultUse only event-observer when your UI layer is not Compose. Add event-observer-compose when the
final observation point lives inside Jetpack Compose Multiplatform.
The fastest path is to start with DataResult and render it where you need it.
val result = dataResultSuccess("Hello")
result.unwrap {
data { value -> println(value) }
error { throwable -> println(throwable.message) }
loading { isLoading -> println("loading=$isLoading") }
}For Compose, convert the upstream state into a ComposableDataResult and render the blocks you care
about.
myFlow.composable
.OnShowLoading { CircularProgressIndicator() }
.OnData { value -> Text(value.toString()) }
.OnError { error -> Text(error.message ?: "Unknown error") }
.Unwrap()For saved state, declare a shared ViewModel and start a new operation on refresh:
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import br.com.arch.toolkit.eventObserver.state.saveResponseState
import br.com.arch.toolkit.result.DataResult
import kotlinx.coroutines.flow.Flow
import kotlinx.serialization.Serializable
@Serializable
data class User(val name: String)
class UsersViewModel(handle: SavedStateHandle) : ViewModel() {
val users by handle.saveResponseState<List<User>>()
val count = users.select { it?.size ?: 0 }
fun refresh(source: () -> Flow<DataResult<List<User>>>) = users.load { source() }
}Observe users.flow() from the View. Its last payload survives completed requests and is restored
through the handle's owner. See the state guide for filters,
plain values, mapping and platform restoration limits.
Public docs live in docs/:
The published MkDocs site is built from the same content and mirrors these pages.
event-observer is Android-facing and integrates with LiveData.event-observer-compose builds on top of event-observer, Flow, and Compose state.Read CONTRIBUTING.md before sending changes.
Copyright 2025 Matheus Corregiari
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
See event-observer-state for one-shot requests, refresh, filters, continuous streams and transformations. Existing Toolkit consumers should follow the migration guide.