Chapter 3. Building data processing chains

 

In this chapter

  • Understanding the different roles of observables
  • Building logical relationships between observables
  • Breaking down a complex problem and solving it with the Rx tools you’ve already learned

Different roles of observables

As you already got a feel for in the preceding chapter, in RxJava the fundamental building blocks are indeed observables. They are technically simple: an observable emits a value whenever it has a new one. It can also complete or throw an error.

This is how all observables work. How they’re used is up to us. Essentially, there are two uses for the Observable class: event observables and reactive variables.

Event observables

You saw observables being used as event sources, such as UI clicks or arriving network requests. This is event processing. RxJava is good at event processing.

This is what’s typical of an observable that’s a plain event source:

  • Emitted events are time-based and can be filtered based on the time.
  • Events contain little or even no data.
  • The clicks observable is a good example of an event observable.

Reactive variables

There’s another side to observables. An observable can be used as a reactive variable that tells everyone whenever it changes, as follows:

  • Emits its possible previous state immediately to new subscribers
  • When _updated, always emits its full state to all subscribers

Let’s look at an example of a reactive variable that indicates the number of oranges in a basket.

Events vs. reactive state

Internal state of an observable

Arrow diagrams and different observable types

Example: Credit card validation form

First step: Expiration date

Credit card number type and checksum

CVC code validation

Putting it all together

Coffee break

The abstraction level of reactive programming

How RxJava works

Summary

sitemap