9

In Rx, what is the point of returning Single for all of our networking request responses, if every call to that method, first of all converts it to an Observable so that it can use flatMap, filters, combineLatest etc.

I get that Observable's have more overhead, Single can only return once, thats all clear. But is it not MORE overhead to create a Single, return it, convert it and now have the Observable we were trying to avoid in the first place.

I don't know if its just Rx I don't like, or how the team here is using it. But it is pissing me off, to no end, how massively overly complicated this is. It really feels to me like this is following a textbook approach while ignoring all the practical details.

<rant>
Next person to say "because its the Rx way", is getting a monitor thrown at their head.
</rant>

Comments
  • 9
    Because its the rx way!
    And now give me my free monitor please ;)
  • 0
    I’d say in this instance there’s likely little gained from doing it Rx-y unless you’re doing transformation / multi-observe on the result.

    I’d stick to a promise and I’m sure Rx has a promise => observable function in there if you need to bridge the gap eventually.
  • 0
    @Brolls Its for Native mobile (RxSwift and RxJava) there is no promise implementation without bringing in another framework. Guys want to use Rx to change how a lot of this stuff works (semi onboard with that idea).

    They aren't using any multi, as far as I can see. They are using a lot of transformations, filtering, skipping etc.

    But my point is:

    func fetchData() -> Single<Data> {...}

    func fetchData2() -> Single<Data> {...}

    Observable.combineLatest(

    fetchData.asObservable(),

    fetchData2.asObservable()

    ).flatmap .............

    If I only ever call fetchData and immediately convert it to an Observable, and never actually use it as a Single ... why should I not just cut out the middle man and return an Observable. Why is the "Rx way" to put a needless step in the middle to convert it
  • 1
    Oh, that looks wrong to me.

    I’d return Observable<Result> from each, no ToSingle and then use something like select many and switch to get the values out, but combinelatest is good too if you want that dual data at the same time.
  • 0
    Just a stab in the dark coming from angular. But would a Single automatically unsubscribe where as an observable you would have to keep the reference and unsubscribe on tear down?
  • 0
    @pain0486 hhhmmm, yes I think you are correct, but is that benefit not negated when you convert it to an Observable?
Add Comment