Subject vs AnonymousSubject

2020-04-07 20:12发布

问题:

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?

回答1:

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