ReactiveState-Kotlin

Facilitates reactive state management and ViewModels with minimal boilerplate. Features include automatic recomputation, on-demand resource allocation, error handling, coroutine-based testing, lifecycle management, and state restoration.

Android
JVM
iOS
Android Native
macOS
watchOS
tvOS
Linux
Windows
Wasm
JS
GitHub stars49
Authorsensody
Dependents1
LicenseApache License 2.0
Creation dateover 6 years ago

Last activity3 days ago
Latest release6.0.0-preview.36 (2 months ago)

ReactiveState

Maven Central

Kotlin Multiplatform ViewModels and reactive state management based on StateFlow.

See the ReactiveState documentation for more details.

Examples

Map/transform a StateFlow:

val number = MutableStateFlow(0)
val doubledNumber: StateFlow<Int> = derived { 2 * get(number) }

Collect two StateFlows (just collect without transforming):

val base = MutableStateFlow(0)
val extra = MutableStateFlow(0)
autoRun {
    if (get(base) + get(extra) > 10) {
        alert("You're flying too high")
    }
}

Multiplatform ViewModels with automatic error handling and loading indicator tracking:

class ExampleViewModel(scope: CoroutineScope, val repository: ExampleRepository) : ReactiveViewModel(scope) {
    val inputFieldValue = MutableStateFlow("default")

    fun submit() {
        // The launch function automatically catches exceptions and increments/decrements the loading indicator.
        // This way you can't forget the fundamentals that have to be always handled correctly.
        launch {
            repository.submit(inputFieldValue.value)
        }
    }
}

Intercept MutableStateFlow:

public val state: MutableStateFlow<String> = MutableStateFlow("value").afterUpdate {
    // This is called every time after someone sets `state.value = ...`
}

Convert StateFlow to MutableStateFlow:

val readOnly: StateFlow<Int> = getSomeStateFlow()
val mutable: MutableStateFlow<Int> = readOnly.toMutable { value: Int ->
    // This is executed whenever someone sets `mutable.value = ...`.
}

See the ReactiveState documentation for more details.

Supported platforms

  • Android
  • JVM
  • All native (including iOS)
  • JS
  • WASM

Installation

Add the package to your build.gradle.kts's dependencies {}:

dependencies {
    // Add the BOM using the desired ReactiveState version
    api(platform("com.ensody.reactivestate:reactivestate-bom:VERSION"))
    // Leave out the version number from now on.

    // Jetpack Compose integration
    api("com.ensody.reactivestate:reactivestate-compose")

    // Android-only integration for Activity/Fragment
    api("com.ensody.reactivestate:reactivestate-android")

    // UI-independent core APIs
    api("com.ensody.reactivestate:reactivestate-core")

    // Utils for unit tests that want to use coroutines
    api("com.ensody.reactivestate:reactivestate-core-test")

    // Android-only unit test extensions
    api("com.ensody.reactivestate:reactivestate-android-test")
}

Also, make sure you've integrated the Maven Central repo, e.g. in your root build.gradle.kts:

subprojects {
    repositories {
        // ...
        mavenCentral()
        // ...
    }
}

License

Copyright 2026 Ensody GmbH, Waldemar Kornewald

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.
Android
JVM
iOS
Android Native
macOS
watchOS
tvOS
Linux
Windows
Wasm
JS
GitHub stars49
Authorsensody
Dependents1
LicenseApache License 2.0
Creation dateover 6 years ago

Last activity3 days ago
Latest release6.0.0-preview.36 (2 months ago)

ReactiveState

Maven Central

Kotlin Multiplatform ViewModels and reactive state management based on StateFlow.

See the ReactiveState documentation for more details.

Examples

Map/transform a StateFlow:

val number = MutableStateFlow(0)
val doubledNumber: StateFlow<Int> = derived { 2 * get(number) }

Collect two StateFlows (just collect without transforming):

val base = MutableStateFlow(0)
val extra = MutableStateFlow(0)
autoRun {
    if (get(base) + get(extra) > 10) {
        alert("You're flying too high")
    }
}

Multiplatform ViewModels with automatic error handling and loading indicator tracking:

class ExampleViewModel(scope: CoroutineScope, val repository: ExampleRepository) : ReactiveViewModel(scope) {
    val inputFieldValue = MutableStateFlow("default")

    fun submit() {
        // The launch function automatically catches exceptions and increments/decrements the loading indicator.
        // This way you can't forget the fundamentals that have to be always handled correctly.
        launch {
            repository.submit(inputFieldValue.value)
        }
    }
}

Intercept MutableStateFlow:

public val state: MutableStateFlow<String> = MutableStateFlow("value").afterUpdate {
    // This is called every time after someone sets `state.value = ...`
}

Convert StateFlow to MutableStateFlow:

val readOnly: StateFlow<Int> = getSomeStateFlow()
val mutable: MutableStateFlow<Int> = readOnly.toMutable { value: Int ->
    // This is executed whenever someone sets `mutable.value = ...`.
}

See the ReactiveState documentation for more details.

Supported platforms

  • Android
  • JVM
  • All native (including iOS)
  • JS
  • WASM

Installation

Add the package to your build.gradle.kts's dependencies {}:

dependencies {
    // Add the BOM using the desired ReactiveState version
    api(platform("com.ensody.reactivestate:reactivestate-bom:VERSION"))
    // Leave out the version number from now on.

    // Jetpack Compose integration
    api("com.ensody.reactivestate:reactivestate-compose")

    // Android-only integration for Activity/Fragment
    api("com.ensody.reactivestate:reactivestate-android")

    // UI-independent core APIs
    api("com.ensody.reactivestate:reactivestate-core")

    // Utils for unit tests that want to use coroutines
    api("com.ensody.reactivestate:reactivestate-core-test")

    // Android-only unit test extensions
    api("com.ensody.reactivestate:reactivestate-android-test")
}

Also, make sure you've integrated the Maven Central repo, e.g. in your root build.gradle.kts:

subprojects {
    repositories {
        // ...
        mavenCentral()
        // ...
    }
}

License

Copyright 2026 Ensody GmbH, Waldemar Kornewald

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.