Observables

Everything starts with an Observable. It's a source of data that you can observe for emitted data (hence the name). In almost all cases (at least in this book), you will be working with the Observable class. It is possible to (and we will!) combine different Observables into one Observable. Basically, it is a universal interface to tap into data streams in a reactive way.

There are lots of different ways of how one can create Observables. The simplest way is to use the .just() method like we did before:

Observable.just("First item", "Second item");

It is usually a perfect way to glue non-Rx-like parts of the code to Rx compatible flow.

When an Observable is created, it is not usually defined when it will start emitting data. If it was created using simple tools such as .just(), it won't start emitting data until there is a subscription to the observable. How do you create a subscription? It's done by calling .subscribe() :

Observable.just("First item", "Second item")
.subscribe();

Usually (but not always), the observable be activated the moment somebody subscribes to it. So, if a new Observable was just created, it won't magically start sending data somewhere.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.50.87