Reactivex with Kotlin 1

Jonathan Monga Android Developer Maishapay, Wenzeasy, CongoBD JonathanMonga @jonathan_monga 2

A little survey 3

A little survey ● Who are Android Developer ? ● Who are not Android Developer ? ● Who develops with Kotlin ? ● Who develops with Java ? ● Who heard about reactivex ? 4

Agenda 5

Agenda ● Boring definitions ● Why RxKotlin ? ● Deep dive into RxKotlin 6

Boring definitions 7

Boring definitions 1) Reactive programming « Is general term thas is focused on reacting to changes, such as data values or events. » Ben christensen. 8

Boring definitions 2) Reactives extensions ● ● An API to handle events synchronously or asynchronously through a flow of event. « Une bibliothèque permettant de composer des programmes asynchrones et basés sur des événements à l’aide de séquences observables. » 9

Boring definitions 3) What’s RxJava or RxKotlin ● ● The java implementation of Reactive extensions. Une Une bibliothèque très légère qui apporte ou ajoute de fonctions d’extensions pratique à RxJava, vu l’interopérabilité entre Java et Kotlin, on peut utiliser RxJava directement avec Kotlin. 10

Boring definitions 4) Reactives extensions (Once upon a time) 2007 2007 — RX RX by by Erik Erik Meijer Meijer 2012 2012 –– RxJava RxJava 11 by by Ben Ben Christensen Christensen 11

Boring definitions 4) Reactives extensions (Once upon a time) 2007 2007 — RX RX by by Erik Erik Meijer Meijer 2012 2012 –– RxJava RxJava 11 by by Ben Ben Christensen Christensen 12

Boring definitions 4) Reactives extensions (Once upon a time) 2013 2013 — RxJava RxJava 22 by by Dávid Dávid Karnok Karnok 2014 2014 –– RxKotlin RxKotlin 11 && 22 by by Ben Ben Christensen Christensen && Thomas Thomas Nield Nield 13

Why RxKotlin ? 14

What is the Problem ? 15

What is the solution? 16

What is the Problem ? 17

What is the solution? 18

What is the Problem ? 19

What is the solution? 20

In conclusion… (a) Get rid of the callback hell. (b) Standard mechanism for error handling (c) It’s a lot simpler than regular threading (d) Simpler way for async operation (e) The same api for every operation (f) The functionnal way (g) Maintainable & Testable code (h) Because of Kotlin. 21

Et Google? 22

Deep dive into RxKotlin 23

Pattern Observer (a) Observable (b) Observer (c) Operateurs (d) Schedulers 24

(a) Observable Is a function that when invoked return 0 ~ ∞ values between now and the end of times. Paul Taylor | Reactive 2015 One value Many values Synchronous/ Pull Fonction Iterator/ Iterable Asynchronous/ Push Promise/ Future Observable 25

(a) Observable Is a function that when invoked return 0 ~ ∞ values between now and the end of times. Paul Taylor | Reactive 2015 One value Many values Synchronous/ Pull Fonction Iterator/ Iterable Asynchronous/ Push Promise/ Future Observable 26

(a) Observable Is a function that when invoked return 0 ~ ∞ values between now and the end of times. Paul Taylor | Reactive 2015 One value Many values Synchronous/ Pull Fonction Iterator/ Iterable Asynchronous/ Push Promise/ Future Observable 27

(a) Observable Is a function that when invoked return 0 ~ ∞ values between now and the end of times. Paul Taylor | Reactive 2015 One value Many values Synchronous/ Pull Fonction Iterator/ Iterable Asynchronous/ Push Promise/ Future Observable 28

(b) Observer It is an interface with 3 main methods. Iterable (Pull) Observer (Push) Get data <T> next() onNext(<T>) To see the error <T> next() throws Exception onError(Throwable) To complete boolean hasnext() onComplete() 29

(b) Observer It is an interface with 3 main methods. Iterable (Pull) Observer (Push) Get data <T> next() onNext(<T>) To see the error <T> next() throws Exception onError(Throwable) To complete boolean hasnext() onComplete() 30

(b) Observer It is an interface with 3 main methods. Iterable (Pull) Observer (Push) Get data <T> next() onNext(<T>) To see the error <T> next() throws Exception onError(Throwable) To complete boolean hasnext() onComplete() 31

(c) Type of Observable 32

(d) Subjects Intersection of Observable and observer 33

(d) Subjects Intersection of Observable and observer 34

(e) How to emit events 35

Operators a) Marble diagrams 36

Operators (b) Type of operators 37

Operators (c) How to use operators 38

Operators Further exemple 39

Schedulers Utiliser pour definir un context d’execution. ● Dans quel thread mon observer va-t-il s’abonner à l’observable ? Use subscribeOn() method. ● Dans quel thread mon observer va-t-il observer ? Use observeOn() method. 40

Schedulers List of schedulers 41

Schedulers Example of schedulers 42

Leaning path & Resource - Training / RxJava2-Android-Samples Guide by Arke Team Reactive Programming with RxJava

  • kaushikgopal/RxJava-Android-Samples - Introduction to RxKotlin Guide Video - Exploring RxJava 2 for Android Jake Wharton - Intro to RxJava for Android - Intro to RxJava Examples Official Site Pratice and Google
  • ReactiveX Official Site
  • Practice in Project
  • ReactiveX GitHub
  • Google and Thinking
  • RxJava GitHub - RxKotlin GitHub - RxJava Category in my Blog 43

Conclusion ● ● ● ● Le pattern Observable/Observer peut s’appliquer à tout RxJava ou RxKotlin sont des technologies approuvées, déjà utiliser chez NetFlix en production. RxJava ou RxKotlin sont des outils très riches. Demande une certaine maîtrise, c’est à dire la courbe d’apprentissage est un peu plus longue. 44

In conclusion… (a) Get rid of the callback hell. (b) It’s a lot simpler than regular threading (c) The same api for every operation (d) Maintainable & Testable code 45

Fin Jonathan Monga Android Developer JonathanMonga @jonathan_monga 46