How to avoid using objects in RX

Therefore, I constantly read that using Subject<T> "bad" - and I agree with the reasoning.

However, I try to make this the best way to avoid using it and to have an example.

Currently, I have an abstract class for my saved configuration classes, which has a protected Save() method that is called whenever a property change is to be saved in the class. This message passes the message to the Subject<T> , which opens through the IObservable<T> interface, which serialization services listen on and serialize the class. It seemed like the most obvious, easiest, and fastest way to do it at the time.

So what would be the RX way to do this without using a theme? Do I instead expose an event and use Observable.FromEventPattern() to subscribe to it? - because it looks more complicated way.

+7
c # system.reactive subject
source share
1 answer

Not so much that using Subject<T> bad, there must be some way to "enter the monad" - that is the academic way of saying "get IObservable<T> ". You need to start something.

The problem with Subject<T> occurs more when it is used from a subscription instead of combining existing observables together. Subjects must exist only at the edges of your Rx technique.

If none of the provided entry points (e.g. FromEvent , FromEventPattern , FromAsync , Return , ToObservable() , etc.) work, you use Subject<T> . And there is no need to add additional complexity just to facilitate the use of one of the above - most of them in any case use objects or similar to objects of construction under covers.

In your case, it sounds like Subject<T> . You can see how to view it with AsObservable() to hide implementation details.

+9
source share

All Articles