What are the differences between observable and subject in rxSwift

What are the differences between observable and subject. When I define a variable of an observable type. It can emit onNext, onComplete, onDispose. However, the subject can do the same. When should observables be used and in which case should I use a theme?

+4
source share
3 answers

To understand the difference between them, it should be mentioned that the Observed :

ReactiveX Observable. . , , , Observable , , .

, ( , ).

, Subject - Observables ( , ):

- , ReactiveX , , . , , , , , .

, , , , , ( , , ( ).


. RxSwift 🐤 3 .

. : RxSwift.

+5

, , , ,

  • ( Rx) - . - . ( onNext, onError, onCompleted), . (, Int, Bool, Array ).

  • , . , - ( self observer). , -, , observer, .
+1

, Observables Subjects, ...

?

, , : http://davesexton.com/blog/post/To-Use-Subject-Or-Not-To-Use-Subject.aspx

TL; DR - . , , , .

You use a theme when you need a hot observable and not yet having an observable to work with. For example, RxCocoa makes extensive use of objects to create observable elements for you that are tied to specific elements of the user interface. They are primarily intended for combining non-Rx code into Rx code and connecting manufacturers to consumers, where for some reason they must be created first.

0
source

Source: https://habr.com/ru/post/1681597/


All Articles