MobX for Kotlin

Core concepts of MobX


Observable is a mutable value that notifies about its changes.

class Task(val id: Int, title: String, description: String, done: Boolean = false) {
    var title by observable(title)

    var description by observable(description)

    var done by observable(done)


Computed is a read-only value that is automatically kept in sync with other observables and computed. Just like an observable, computed value notifies about its changes.

    val count by computed { todoList.size }
    val pending by computed { todoList.count { !it.done } }
    val done by computed { count - pending }


Autorun runs a reaction when its dependencies (observables and computed) are changed.

val disposable = autorun {
    containerView.title.text = task.title
    containerView.description.text = task.description

In this example logging runs immediately and then on any change of appleCount, bananaCount or fruitCount. There are no needs to subscribe to these observables manually! Another example of reaction is UI updating.


Actions allow to mutate observables. Actions batch mutations, so a notifications will occur only after an action has finished.

fun clear() = action("clearAllTasks") {

A string argument of action is a payload. It can be used for logging.


Please check out app


Add it in your root build.gradle at the end of repositories:

Step 1. Add the JitPack repository to your build file

allprojects {
    repositories {
        maven { url '' }

Step 2. Add the dependency

dependencies {
    implementation 'com.github.RomanPozdeev:MobX:0.1'


Latest posts