Search code examples
javascriptrxjsrxjs5

Subject vs AnonymousSubject


What's the difference between Subject and AnonymousSubject in RxJS 5? I've searched the internet but didn't find any info about AnonymousSubject.

I've found an example on the web

Subject.create(observer, observable);

Looking into rxjs source code I saw that this creates and AnonymousSubject. Can you also come up with an example when is good to use AnonymousSubject?


Solution

  • The AnonymousSubject doesn't subscribe itself to the source Observable. It just connects the source and destination.

    I don't know what a typical use-case for AnonymousSubject looks like but it's used inside Subject.lift().

    Also see: RxJs Subject.subscribe method not working as expected