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

ReactiveX Basics

ReactiveX Basics

The main principles and concepts used in the ReactiveX world

Catalin Morosan

February 03, 2016
Tweet

More Decks by Catalin Morosan

Other Decks in Technology

Transcript

  1. A combination of the best ideas from • Observer pattern

    • Iterator pattern • functional programming
  2. Everywhere and meant for everything • Frontend ◦ UI events

    / API responses ◦ web / mobile / desktop
  3. Everywhere and meant for everything • Frontend ◦ UI events

    / API responses ◦ web / mobile / desktop • Backend
  4. Everywhere and meant for everything • Frontend ◦ UI events

    / API responses ◦ web / mobile / desktop • Backend ◦ concurrency
  5. Cold vs Hot Observables • cold - waits until subscriber

    subscribes to it before it begins emitting items
  6. Cold vs Hot Observables • cold - waits until subscriber

    subscribes to it before it begins emitting items • hot - may begin emitting items as soon as it is created
  7. Scheduler • subscribeOn - thread the Observable runs on •

    observeOn - thread the Observable uses to send notifications to the subscribers
  8. Scheduler • subscribeOn - thread the Observable runs on •

    observeOn - thread the Observable uses to send notifications to the subscribers • by default Observable runs and sends notifications on the current thread
  9. Operators • most operate on Observable and return an Observable

    • you can apply operators one after the other, in a chain
  10. Operators • most operate on Observable and return an Observable

    • you can apply operators one after the other, in a chain • extreme power in transforming one stream of elements into a completely different stream
  11. Operators • most operate on Observable and return an Observable

    • you can apply operators one after the other, in a chain • extreme power in transforming one stream of elements into a completely different stream • large number of operators to choose from
  12. Subject • acts as an Observer ◦ it can subscribe

    to one or more Observables • acts as an Observable
  13. Subject • acts as an Observer ◦ it can subscribe

    to one or more Observables • acts as an Observable ◦ it can reemit the items it observes
  14. Subject • acts as an Observer ◦ it can subscribe

    to one or more Observables • acts as an Observable ◦ it can reemit the items it observes ◦ it can also emit new items
  15. Subject • acts as an Observer ◦ it can subscribe

    to one or more Observables • acts as an Observable ◦ it can reemit the items it observes ◦ it can also emit new items • 4 types of Subjects designed for specific use cases
  16. “ReactiveX is more than an API, it’s an idea and

    a breakthrough in programming.” reactivex.io