Thursday, 20 April 2023

Kotlin - Observer

 Rxjava - 

Observer - Based on data view willl render (react) karega.

trotling -> making stream for execution (Means clicks event fire krege ek particular duration m taki same event again & again call n ho) 

3 Major Component are there -

    1) Observable

    2) Observer

    3) Operator 


class MainActivity : AppCompatActivity() {

private var TAG:String = "MainActivity"

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

var btn_throttleFirst : Button = findViewById(R.id.btn_throttleFirst)

btn_throttleFirst.clicks()
.throttleFirst(15000,TimeUnit.MILLISECONDS)
.subscribe {
Log.d(TAG,"throttleFirst duration : 15000 MLS")
}

simpleObserver()
}

private fun simpleObserver(){
var list = listOf<String>("member 1","member 2","member 3")
val observable = io.reactivex.rxjava3.core.Observable.fromIterable(list)

observable.subscribe(object : io.reactivex.rxjava3.core.Observer<String>{
override fun onSubscribe(d: Disposable) {
Log.d(TAG,"onSubscribe")
}

override fun onError(e: Throwable) {
Log.d(TAG,"onError")
}

override fun onComplete() {
Log.d(TAG,"onComplete")
}

override fun onNext(t: String) {
Log.d(TAG,"onNext")
}

})

}
}


output -

 throttleFirst duration : 15000 MLS


No comments:

Post a Comment

Kotlin - Observer

 Rxjava -  Observer - Based on data view willl render (react) karega. trotling -> making stream for execution (Means clicks event fire kr...