Skip to content

w2sv/ReversibleState

Repository files navigation

ReversibleState

Maven Central Version GitHub release (latest by date including pre-releases) Build GitHub

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.

🎯 Targets

  • JVM
  • iOS Arm64
  • iOS Simulator Arm64

🚀 Installation

dependencies {
    implementation("io.github.w2sv:reversible-state:<version>")
}

For Kotlin Multiplatform projects:

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("io.github.w2sv:reversible-state:<version>")
        }
    }
}

Usage

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.

📄 License

Apache License 2.0. See LICENSE.

About

Reversible state holders for Kotlin Multiplatform

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors