Observables and operators
Up until this point, we’ve used observables as a way to capture the data that came from the backend API using the subscribe
method, but let’s take a step back and ask what an observable is and why we don’t just use JavaScript promises.
Let’s use a table to organize our explanation:
Single |
Multiple |
|
Synchronous |
Function |
Iterator |
Asynchronous |
Promise |
Observable |
Table 9.1 – Types of objects by requirement
When we need to perform synchronous processing and expect a return value, we use a function. If we need a collection of synchronous values, we use an object of the Iterator
type. We use promises when we need the return value of a function, but its processing is asynchronous...