konmik / nucleus

Nucleus is an Android library, which utilizes the Model-View-Presenter pattern to properly connect background tasks with visual parts of an application.
MIT License
1.97k stars 253 forks source link

DeliveryReplay is weird #124

Closed lectricas closed 7 years ago

lectricas commented 7 years ago

Hi. What I want is to turn RxBinding callback back to my acitivity. Restartable is not suitable for that, however I need my view object in order to call the callback method. getView is depricated, so I tried to use deliveryFirst:

    public void listenFieldsForClick(Observable<Void> clicksFrom, Observable<Void> clicksTo) {
        deliverReplay().call(clicksFrom.map(aVoid -> aVoid)).subscribe(
                delivery -> delivery.split(SelectRouteFragment::clearEditTextFrom, this::onError)
        );

        deliverReplay().call(clicksTo.map(aVoid -> aVoid)).subscribe(
                delivery -> delivery.split(SelectRouteFragment::clearEditTextFrom, this::onError)
        );
    }

so this is my method, which listens fields for click event by RxView.clicks(myview);

And... this seems kinda huge for just one simple callback. RestartableFirst for example make more actions and code looks better and more readable. Second< I have to do this map call (clicksFrom.map(aVoid -> aVoid)) bacause call somehow don't understand that I'm passing an object there. What I'm doing wrong?

konmik commented 7 years ago

In Nucleus presenter is not supposed to control view.

Controlling view (if you really need it) with Rx is weird as I personally think, because Rx is more complex than simple method calls.

lectricas commented 7 years ago

@konmik , but what about rxbinding? I think it's nice to get rid of logic in my activity. I took this project as an example https://github.com/matzuk/TestableCodeMobius Can you show your way of handling the scenario when button status depends on editText status?

konmik commented 7 years ago

I have no idea how and why someone will need to control presenter from view with rx(bindings) to control view from presenter back. This type of ping-pong logic is not efficient. There many ways to split the app logic into parts, and ping-pong is the most complicated and less efficient one.

lectricas commented 7 years ago

@konmik I agree that bindings require more code and sometimes unreadable. can you please show some examples of how to split the logic?