makkasi
makkasi

Reputation: 7318

What observable methods subscribe for the result, and what methods do not, and just pass the stream when using Observable

  1. Which of the Observable methods do "subscribe" for the result? For example flatMap subscribes to the result of the first Observable and passes the result without calling the subscribe method.
  2. Is there way to be sure what the Observable methods (flatMap, mergeMap, forkJoin, concat, subscribe ...) return compile time, whether is subscription or is Observable? I'm often confused what is the result of the methods.
  3. Is there some categorization of this type for the rxjs methods?
  4. Is there site or tool that I can use to simulate this behavior, and to understand it better.?

Upvotes: 0

Views: 194

Answers (1)

Picci
Picci

Reputation: 17762

The only method that subscribes to an Observable is subscribe().

flatMap (also known as mergeMap), switchMap, map, and so on are operators that transform the original sequence of events. These operators though return an Observable.

RxJs Observables are cold, which means they are activated only when they are subscribed.

RxJs is the javascript implementation of the ReactiveX APIs. If you want to understand in more details how Observables work you can start from the ReactiveX documentation (http://reactivex.io/).

A great course that explains you in details the ReactiveX patterns and the reasons why they are so useful in Angular is the following [https://angular-university.io/course/reactive-angular-architecture-course].2

A third interesting discussion about switchMap, one of the most useful and a bit mysterious operators, can be found here blog.angular-university.io/rxjs-switchmap-operator/

Upvotes: 1

Related Questions