Skip to content

Migrating to 2.0

2.0 changes the Maven coordinates and packages and tightens several runtime guarantees. Most apps need the first two steps and a review of the behaviour changes below.

1. Update the dependencies

1.x 2.0
com.trendyol:transmission com.yigitozgumus:transmission
com.trendyol:transmission-viewmodel com.yigitozgumus:transmission-viewmodel
com.trendyol:transmission-test com.yigitozgumus:transmission-test
implementation("com.yigitozgumus:transmission:2.0.0-beta02")

2. Update the imports

Packages moved from com.trendyol.transmission* to com.yigitozgumus.transmission*. Replacing com.trendyol. with com.yigitozgumus. in imports is enough:

// 1.x
import com.trendyol.transmission.transformer.Transformer
import com.trendyol.transmissionviewmodel.RouterViewModel
// 2.0
import com.yigitozgumus.transmission.transformer.Transformer
import com.yigitozgumus.transmissionviewmodel.RouterViewModel

Update ProGuard/R8 rules that name these packages the same way.

3. Review the behaviour changes

Change What to do
Routers no longer join the global router by default. Call registerToGlobalRouter() on every router that exchanges effects or queries with other routers (RouterViewModelConfig(registerToGlobalRouter = true) for ViewModels).
A throwing computation fails the caller's compute(...) with the same exception; a missing data holder or computation throws ContractNotFoundException. Handle failures where you call compute / getData, instead of checking for null.
Handlers can't change after the router initializes. Register every handler in configure { } before the router starts.
onSignal<T> / onEffect<T> registered twice in configure { } both run, in order. Remove accidental duplicates.
streamData / streamEffect drop the oldest items beyond Capacity instead of slowing transformers down. Use Capacity.Unlimited if every item must reach observers.
RouterViewModel.streamDataAsState starts eagerly (was WhileSubscribed()). Pass started explicitly to keep the old behaviour; prefer streamDataAsState(contract, initial) for data holders.
process, send and tryProcess share one ordered inbox; send no longer waits for transformers. Nothing, unless you relied on send for backpressure.

4. Move to the builder API

The classic API (Transformer subclasses with configure { }, Contract factories, TransmissionRouter { }, RouterViewModel and the TransmissionTest harness) is deprecated. It keeps working in 2.x; checkpoints will be removed in 3.0. Builder and classic transformers share routers, so you can move one feature at a time.

Before:

class CounterTransformer : Transformer() {
    private val count = dataHolder(Count(0), countContract)

    init {
        configure {
            onSignal<Increment> { count.update { Count(it.value + 1) } }
        }
    }

    companion object {
        val countContract = Contract.dataHolder<Count>()
    }
}

class CounterViewModel : RouterViewModel(setOf(CounterTransformer())) {
    val count = streamDataAsState(CounterTransformer.countContract, Count(0))
}

After:

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 = router.state(Counter.count)
    fun increment() = router.process(Increment)
}

Step by step:

  1. Contracts: replace each feature's Contract.* values with a Contracts object (Contracts).
  2. Transformers: turn each class into a transformer(Contracts) { } function (Transformer).
  3. Handlers: onSignal and onEffect become on<T>; checkpoints become awaitSignal (Handlers).
  4. Routers: replace RouterViewModel and TransmissionRouter { } with viewModelScope.router(...) (Router).
  5. Tests: move to the test DSL (Testing).

During the move, a classic transformer can use a builder handle's contract: compute(Cart.summary.contract).

What you get

  • Messages to one transformer are handled one at a time, in arrival order: plain var state is safe.
  • A failing handler is reported to onError; the transformer keeps working.
  • pauseOn gives up the turn while it waits, so a transformer can release its own checkpoint.
  • Signals sent before the router finishes initializing are delivered.
  • compute round trips take under a microsecond instead of tens of microseconds.

The full list is in the Changelog.