Skip to content

Transmission

Transmission is a Kotlin Multiplatform library for asynchronous communication between business-logic components. Components talk through typed Signals, Effects, Data and contract-based queries, without holding references to each other.

dependencies {
    implementation("com.yigitozgumus:transmission:2.0.0-beta02")
    testImplementation("com.yigitozgumus:transmission-test:2.0.0-beta02")   // optional
}

New in 2.0

Each transformer processes its messages one at a time and in order, so plain var state inside a transformer is safe; a failing handler no longer stops a transformer; routers are isolated unless they opt in to the global router; and queries are answered directly, about 50 times faster. 2.0 moves to the com.yigitozgumus group and packages. See Migrating to 2.0.

Quick Start

import com.yigitozgumus.transmission.Contracts
import com.yigitozgumus.transmission.Transmission
import com.yigitozgumus.transmission.router
import com.yigitozgumus.transmission.state
import com.yigitozgumus.transmission.transformer

data object Increment : Transmission.Signal
data class Count(val value: Int) : Transmission.Data

object Counter : Contracts() {
    val count by state(Count(0))
}

fun counterTransformer() = transformer(Counter) {
    val count = state(Counter.count)
    on<Increment> { count.update { Count(it.value + 1) } }
}

class CounterViewModel : ViewModel() {
    private val router = viewModelScope.router("counter", counterTransformer())
    val count: StateFlow<Count> = router.state(Counter.count)
    fun increment() = router.process(Increment)
}

Core Concepts

  • Signals come from outside the router, such as the UI. Effects travel between transformers. Both are messages a transformer handles with on<T>.
  • Data is what observers receive: published state and anything a handler emits.
  • Transformers own state and handle messages one at a time, in order. Build them with transformer { }.
  • Contracts objects declare a feature's state, queries and commands; handlers call them like functions (Cart.summary(), Cart.clear()).
  • Routers connect transformers. Create them with scope.router(...); call global() to talk to other routers.
  • Tests use transformer.test { send(...); awaitState(...) } from transmission-test.

The classic API (transformer classes with configure { }, Contract factories, RouterViewModel) is deprecated. It keeps working in 2.x; each page below ends with a table mapping it to the builder API, and its old reference is under Classic API.

Documentation

API Reference

📚 API Documentation - Generated Dokka reference for public classes and methods.