Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive Programming in Kotlin|Android

Toan Tran
December 12, 2020

Reactive Programming in Kotlin|Android

A brief talk on the concept of Reactive programming and how it was realized in Android development.

Toan Tran

December 12, 2020
Tweet

More Decks by Toan Tran

Other Decks in Programming

Transcript

  1. Reactive Programming in Kotlin|Android 1. The ultimate goal of app

    development. 2. Introducing Reactive Programming. 3. Realize RP with Kotlin in Android. 4. Some common patterns we may use daily. 5. Key-takeaways.
  2. 1. Introducing Reactive Programming 1. A programming paradigm. 2. Based

    on 3 pillars: ◦ Data streams. ◦ Asynchronous processing. ◦ Functional programming.
  3. 1. Introducing Reactive Programming Reactive Programming vs … Val data

    = getDataFromStream() If (data is matched condition) { ui.display() } getDataFromStream(). .filter( condition ) .subscribe { ui.display() }
  4. 1. Introducing Reactive Programming Reactive Programming vs … Val remote

    = getDataFromStream() // blocking call Val local = readFromLocalDB() // blocking call If (remote is matched condition 1 AND local matched condition 2 ) { ui.display() } getDataFromStream(). concat(readFromLocalDB) .filter( condition1 AND condition 2 ) .subscribe { ui.display() }
  5. 1. Introducing Reactive Programming Reactive Programming vs … Callback<Remote> remote

    = getDataFromStream() Callback<Local> local = readFromLocalDB() remote.execute(THREAD_IO).onResult { res1 -> local.excecute(THREAD_IO).onResult {res2 -> if (condition 1 and condition 2) { runOnnUIThread { ui.display() } } } } getDataFromStream(). concat(readFromLocalDB) .subcribeOn(THREAD_IO) .filter( condition1 AND condition 2 ) .observerOn(UI_THREAD) .subscribe { ui.display() }
  6. 3. Realize RP in Kotlin/Android • http://reactivex.io/ • RxJava, RxJS,

    RxSwift, etc • Early adopted by big names: Netflix, Microsoft, GitHub, SoundCloud, etc
  7. 3. Realize RP in Kotlin/Android RxJava: - Create - Combine

    - Subscribe RxAndroid: - Android threading
  8. 5. Key takeaways 1. Reactive Programming is paradigm based on

    async stream processing with the support of functional programming. 2. Realize with ReactiveX language implementations: RxJava, RxKotlin, RxSwift, RxJS 3. Rx provided with set of common tools/pattern to solve data manipulation in an asynchronous manner.