3. What’s the Subject?
A Subject is a sort of bridge or proxy that acts both as a
Subscriber and as an Observable. Because it is a Subscriber,
it can subscribe to one or more Observables, and because it
is an Observable, it can pass through the items it observes
by reemitting them, and it can also emit new items.
Subject = Observable + Subscriber
Observable 과 Subscriber 연결하는 다리같은 역할
Subject는 Subscriber과 Observable 두가지 모두를 하는 객체
Subject는 Observer처럼 Observable을 구독할 수 있고 Obserable처럼 새로운 아이템을 발행하거나
전달받은 아이템을 바이패스할 수 있다.
확실한건 Observable에 된다는것은 Observer나 여타 Subject가 자신을 구독 할 수 있다는 점이다.
PublishSubject와 비슷하지만 구독전에 한건이라도 이벤트가 발생하면 구독 시점에 해당 이벤트도 같이 전달 받습니다.
* Observer가 관찰하는 순간 가장 최근의 값을 발행해야하므로 초기값이 필요합니다.
사용자가 다운로드 받는 중에 몇 %를 다운 받았는지 보고 싶다.
이런경우에는 behaviorSubject를 통해서 마지막에 받았던것을 백업해주는 용도로 사용되어 질 수 있다.