rxDatabindings

Additional

Language
Kotlin
Version
N/A
Created
Nov 10, 2016
Updated
Jan 30, 2018
Owner
Stepan Goncharov (stepango)
Contributors
Stepan Goncharov (stepango)
nekdenis
2
Activity
Badge
Generate
Download
Source code
APK file

Advertisement

RxDatabindings

RxJava2 extensions for Android Databindings library

Add RxDataBindings to your build.gradle

compile "com.stepango.rxdatabindings:rxdatabindings:1.1.1"

Basic example of usage:

interface ViewModelState : Parcelable {
    val text: ObservableString
    val counter: ObservableInt
}

data class ViewModelStateImpl(
        override val text: ObservableString = ObservableString(),
        override val counter: ObservableInt = ObservableInt()
) : ViewModelState, AutoParcelable

class ViewModel(val state: ViewModelState) : ViewModelState by state {

    init {
        counter.observe()
                .setTo(text) { "Wow! You count till $it" }
                .doOnNext { Log.d("THREAD", Thread.currentThread().name) }
                .subscribe()
    }

    fun incCounter() = counter.inc(10)
    fun decCounter() = counter.dec(0)

}

This library depends on kOptional at the moment. This dependency will be removed in upcoming release