Slide 1

Slide 1 text

Reactive Programming Aung Kyaw Paing

Slide 2

Slide 2 text

A little bit about myself • 2 years in Android Development • Have released a couple of apps • Android Dev at Nex • Final year CS student

Slide 3

Slide 3 text

What’s Reactive Programming?

Slide 4

Slide 4 text

What’s Reactive Programming? Reactive programming is programming with asynchronous data streams. Source : https://gist.github.com/staltz/868e7e9bc2a7b8c1f754

Slide 5

Slide 5 text

What’s Reactive Programming? Reactive programming is programming with asynchronous data streams. Source : https://gist.github.com/staltz/868e7e9bc2a7b8c1f754

Slide 6

Slide 6 text

Capturing Double Click Step 1 : Capture click events in a stream Step 2 : Group click events within a time period Step 3 : Count the grouped click events in each time period Step 4 : Filter groups that contains 2 or more clicks

Slide 7

Slide 7 text

Capturing Double Click Source : https://gist.github.com/staltz/868e7e9bc2a7b8c1f754

Slide 8

Slide 8 text

Buffer Bundles data emitted by an observable within a time period and emit this bundle instead of the original data

Slide 9

Slide 9 text

Map Transform data emitted by an observable using a function

Slide 10

Slide 10 text

Filter Emit data if and only if it passes a test

Slide 11

Slide 11 text

Capturing Double Click

Slide 12

Slide 12 text

Capturing Double Click

Slide 13

Slide 13 text

Meet ReactiveX An API for asynchronous programming with observable streams http://reactivex.io/

Slide 14

Slide 14 text

Meet ReactiveX Observable Observer

Slide 15

Slide 15 text

Why Rx?

Slide 16

Slide 16 text

Why Rx? Source : http://jakewharton.com/exploring-rxjava-2-for-android/

Slide 17

Slide 17 text

Why Rx?

Slide 18

Slide 18 text

Why Rx?

Slide 19

Slide 19 text

Why Rx?

Slide 20

Slide 20 text

Why Rx?

Slide 21

Slide 21 text

Why Rx?

Slide 22

Slide 22 text

Why Rx?

Slide 23

Slide 23 text

Why Rx?

Slide 24

Slide 24 text

Real World Example • Handling Network and Cache Data • AutoComplete Search

Slide 25

Slide 25 text

Handling Network And Cache Data

Slide 26

Slide 26 text

MergeDelayError Combine multiple observable of same type into one observable

Slide 27

Slide 27 text

Handling Network And Cache Data

Slide 28

Slide 28 text

Handling Network And Cache Data

Slide 29

Slide 29 text

Handling Network And Cache Data

Slide 30

Slide 30 text

Concat Combines multiple observable but respect the order in which the observables are subscribed

Slide 31

Slide 31 text

Handling Network And Cache Data

Slide 32

Slide 32 text

Publish Makes a observable connectable

Slide 33

Slide 33 text

TakeUntil Discard data emitted by a observable after a second observable emits it first data or terminates

Slide 34

Slide 34 text

Handling Network And Cache Data

Slide 35

Slide 35 text

AutoComplete Search

Slide 36

Slide 36 text

Debounce Emits only if the observable after a period of time have passed without emitting a data

Slide 37

Slide 37 text

Flatmap Transform data emitted from an observable into another observable of different type

Slide 38

Slide 38 text

Holy Trinity of RxConversation map R => T flatMap R => Observable compose Observable => Observable

Slide 39

Slide 39 text

AutoComplete Search

Slide 40

Slide 40 text

AutoComplete Search (flatmap)

Slide 41

Slide 41 text

Concatmap Transform data emitted from an observable into another observable of different type but it respects the order

Slide 42

Slide 42 text

AutoComplete Search

Slide 43

Slide 43 text

AutoComplete Search (concatmap)

Slide 44

Slide 44 text

Switchmap Switchmap works like Concatmap but it will immediately unsubscribe to pervious items emitted from the stream as soon as an observable emits an item into the stream

Slide 45

Slide 45 text

AutoComplete Search

Slide 46

Slide 46 text

AutoComplete Search (switchmap)

Slide 47

Slide 47 text

Suggested Links The Introduction to Reactive Programming You’ve been missing https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 Exploring RxJava 2 for Android http://jakewharton.com/exploring-rxjava-2-for-android/ Learning Rx by example Part 1 & 2 https://www.youtube.com/watch?v=k3D0cWyNno4 https://vimeo.com/190922794 Rx-Android-Samples https://github.com/kaushikgopal/RxJava-Android-Samples Rxify Series https://medium.com/@ragdroid

Slide 48

Slide 48 text

Question Time