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

0991ca4bc363163337f7b02b98af538a?s=128

Aung Kyaw Paing

December 17, 2016
Tweet

More Decks by Aung Kyaw Paing

Other Decks in Programming

Transcript

  1. Reactive Programming Aung Kyaw Paing

  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
  3. What’s Reactive Programming?

  4. What’s Reactive Programming? Reactive programming is programming with asynchronous data

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

    streams. Source : https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
  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
  7. Capturing Double Click Source : https://gist.github.com/staltz/868e7e9bc2a7b8c1f754

  8. Buffer Bundles data emitted by an observable within a time

    period and emit this bundle instead of the original data
  9. Map Transform data emitted by an observable using a function

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

    test
  11. Capturing Double Click

  12. Capturing Double Click

  13. Meet ReactiveX An API for asynchronous programming with observable streams

    http://reactivex.io/
  14. Meet ReactiveX Observable Observer

  15. Why Rx?

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

  17. Why Rx?

  18. Why Rx?

  19. Why Rx?

  20. Why Rx?

  21. Why Rx?

  22. Why Rx?

  23. Why Rx?

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

    AutoComplete Search
  25. Handling Network And Cache Data

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

  27. Handling Network And Cache Data

  28. Handling Network And Cache Data

  29. Handling Network And Cache Data

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

    the observables are subscribed
  31. Handling Network And Cache Data

  32. Publish Makes a observable connectable

  33. TakeUntil Discard data emitted by a observable after a second

    observable emits it first data or terminates
  34. Handling Network And Cache Data

  35. AutoComplete Search

  36. Debounce Emits only if the observable after a period of

    time have passed without emitting a data
  37. Flatmap Transform data emitted from an observable into another observable

    of different type
  38. Holy Trinity of RxConversation map R => T flatMap R

    => Observable<T> compose Observable<R> => Observable<T>
  39. AutoComplete Search

  40. AutoComplete Search (flatmap)

  41. Concatmap Transform data emitted from an observable into another observable

    of different type but it respects the order
  42. AutoComplete Search

  43. AutoComplete Search (concatmap)

  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
  45. AutoComplete Search

  46. AutoComplete Search (switchmap)

  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
  48. Question Time