anchor
0.1.8indexedLightweight, type-safe state-management architecture with expressive DSL, lifecycle-aware state retention, granular state observation, effect/signal handling, and cancellable asynchronous jobs for reactive UI development.
Lightweight, type-safe state-management architecture with expressive DSL, lifecycle-aware state retention, granular state observation, effect/signal handling, and cancellable asynchronous jobs for reactive UI development.
Anchor is a lightweight, type-safe state management architecture for Kotlin Multiplatform projects, specifically designed for Jetpack Compose. It leverages Kotlin's modern features like Context Receivers and SAM conversions to provide a clean, expressive, and powerful DSL.
Visit kioba.github.io/anchor/ for the full documentation!
Add the dependencies to your build.gradle.kts:
dependencies {
implementation("dev.kioba.anchor:anchor:0.1.7")
implementation("dev.kioba.anchor:anchor-compose:0.1.7")
testImplementation("dev.kioba.anchor:anchor-test:0.1.7")
}
Defining a simple Counter component with Anchor:
data class CounterState(val count: Int = 0) : ViewState
typealias CounterAnchor = Anchor<EmptyEffect, CounterState, Nothing>
fun RememberAnchorScope.counterAnchor(): CounterAnchor =
create(initialState = ::CounterState, effectScope = { EmptyEffect })
fun CounterAnchor.increment() {
reduce { copy(count = count + 1) }
}
fun CounterAnchor.decrement() {
reduce { copy(count = count - 1) }
}
@Composable
fun CounterUi() {
RememberAnchor(scope = { counterAnchor() }) {
val count = collectState { it.count }
Column {
Text("Count: $count")
Row {
Button(onClick = anchor(CounterAnchor::decrement)) { Text("-") }
Button(onClick = anchor(CounterAnchor::increment)) { Text("+") }
}
}
}
}
For comprehensive details, check out our documentation:
Contributions are welcome! If you'd like to help improve Anchor, feel free to:
When contributing, please ensure your code follows the existing style and includes appropriate tests.
Copyright 2026 Karoly Somodi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.
Surfaced from shared tags and platforms — no rankings paid for.