Marble Diagram

아래로 내려오는 점선 화살표는 입력, 출력을 의미한다. 아이템들이 Observable 에 의해 방출될 때 onNext() 가 호출되며, 파이프(|)에서는 onComplete() 가 호출된다. X 에서는 onError() 가 호출된다.

Operators:

  • Observable -> Operators -> Observer
  • We can apply a chain of operators on an Observable where each output of one operator is the input of the next operator. Using these operators we can modify, combine or filter the data streams emitted by an Observable.

The essential concepts in RxJS which solve async event management are:

  • Observable: represents the idea of an invokable collection of future values or events.
  • Observer: is a collection of callbacks that knows how to listen to values delivered by the Observable.
  • Subscription: represents the execution of an Observable, is primarily useful for cancelling the execution.
  • Operators: are pure functions that enable a functional programming style of dealing with collections with operations like map, filter, concat, flatMap, etc.
  • Subject: is the equivalent to an EventEmitter, and the only way of multicasting a value or event to multiple Observers.
  • Schedulers: are centralized dispatchers to control concurrency, allowing us to coordinate when computation happens on e.g. setTimeout or requestAnimationFrame or others.

Filter

  • 원을 찾는 필터

Map

  • 원을 다이아몬드로 변환

FlatMap

  • Observable 이 방출한 항목을 Observable 로 변환한 다음 단일 Observable 로 병합
  • flatMap 은 Item 대신 Observable 을 방출

ConcatMap

  • flatMap 과 유사하지만 Observable 의 순서를 보장

SwitchMap

  • 항상 최신 Observable 을 반환
  • convert an Observable that emits Observables into a single Observable that emits the items emitted by the most-recently-emitted of those Observables
  • Switch subscribes to an Observable that emits Observables. Each time it observes one of these emitted Observables, the Observable returned by Switch unsubscribes from the previously-emitted Observable begins emitting items from the latest Observable. Note that it will unsubscribe from the previously-emitted Observable when a new Observable is emitted from the source Observable, not when the new Observable emits an item. This means that items emitted by the previous Observable between the time the subsequent Observable is emitted and the time that subsequent Observable itself begins emitting items will be dropped (as with the yellow circle in the diagram above).