Reversible state holders for Kotlin Multiplatform.
ReversibleState tracks an editable value alongside an applied value, exposes whether there are uncommitted changes, and provides commit/revert operations for pushing or discarding edits.
- JVM
- iOS Arm64
- iOS Simulator Arm64
dependencies {
implementation("io.github.w2sv:reversible-state:<version>")
}For Kotlin Multiplatform projects:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.w2sv:reversible-state:<version>")
}
}
}val appliedState = MutableStateFlow("saved")
val state = ReversibleStateFlow(
scope = scope,
appliedState = appliedState,
commitState = { appliedState.value = it }
)
state.value = "draft"
check(state.isDirty.value)
suspend fun save() {
state.commit()
}
state.revert()Use ReversibleStateComposition to group several reversible states and commit or revert only the dirty children.
Apache License 2.0. See LICENSE.