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