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

Reactive Programming

Reactive Programming

Reactive Programming Talk @DevCon Yangon 2016. Reactive Programming explained with real world examples written in Java including Capturing Double Click, Loading Network and Cache Data and implementing AutoComplete Search

Aung Kyaw Paing

December 17, 2016
Tweet

More Decks by Aung Kyaw Paing

Other Decks in Programming

Transcript

  1. Reactive
    Programming
    Aung Kyaw Paing

    View Slide

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

    View Slide

  3. What’s Reactive Programming?

    View Slide

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

    View Slide

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

    View Slide

  6. 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

    View Slide

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

    View Slide

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

    View Slide

  9. Map
    Transform data emitted by an observable using a
    function

    View Slide

  10. Filter
    Emit data if and only if it passes a test

    View Slide

  11. Capturing Double Click

    View Slide

  12. Capturing Double Click

    View Slide

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

    View Slide

  14. Meet ReactiveX
    Observable
    Observer

    View Slide

  15. Why Rx?

    View Slide

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

    View Slide

  17. Why Rx?

    View Slide

  18. Why Rx?

    View Slide

  19. Why Rx?

    View Slide

  20. Why Rx?

    View Slide

  21. Why Rx?

    View Slide

  22. Why Rx?

    View Slide

  23. Why Rx?

    View Slide

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

    View Slide

  25. Handling Network And Cache Data

    View Slide

  26. MergeDelayError
    Combine multiple observable of same type into
    one observable

    View Slide

  27. Handling Network And Cache Data

    View Slide

  28. Handling Network And Cache Data

    View Slide

  29. Handling Network And Cache Data

    View Slide

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

    View Slide

  31. Handling Network And Cache Data

    View Slide

  32. Publish
    Makes a observable connectable

    View Slide

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

    View Slide

  34. Handling Network And Cache Data

    View Slide

  35. AutoComplete Search

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  39. AutoComplete Search

    View Slide

  40. AutoComplete Search (flatmap)

    View Slide

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

    View Slide

  42. AutoComplete Search

    View Slide

  43. AutoComplete Search (concatmap)

    View Slide

  44. 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

    View Slide

  45. AutoComplete Search

    View Slide

  46. AutoComplete Search (switchmap)

    View Slide

  47. 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

    View Slide

  48. Question Time

    View Slide