question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should MviPresenter offer getViewStateObservable() or not?

See original GitHub issue

The idea of MviPresenter.getViewStateObservable() is that another MVI UI component could use this observable as “intent” for rendering it’s own view state.

i.e: AView has APresenter. BView has BPresenter that takes APresenter.getViewStateObservable() as input (i.e. as intent) to coordinate BView. In other words: Changing AView has impact to what BView displays.

However, I think that usually both UI components should rather “observe” both the same “model” from business logic. Offering getViewStateObservable() may lead to the wrong impression that getViewStateObservable() should be used everywhere. Actually, I think that there are only very few edge cases where using MviPresenter.getViewStateObservable() makes sense and should be preferred over “observing the same model”.

Furthermore, parent - child relations are not a good idea and MviPresenter.getViewStateObserable() allows you to build such parent-child relations (attention: cycles in your dependency graph).

As compromise we could move getViewStateObservable() to MviBasePresenter (rather than MviPresenter and make getViewStateObservable() protected.

By doing so a developer explicitly has to override getViewStateObservable() with public visibility in his own presenter to make getViewStateObservable() visible for other presenters (to establish a child-parent relationship).

Note: child-parent relation may not be the correct word because there is no Presenter.getParentPresenter() method etc. so that is not really a parent - child relation from a hierarchical point of view, but I hope you get what I’m trying to say with “parent-child” relation.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sockeqwecommented, Mar 14, 2017

oops, forgot to update this:

Finally I have changed mind again: getViewStateObservable() has protected visibility in 3.0.

Testing can be done easily even without getViewStateObservable()

0reactions
sockeqwecommented, Mar 9, 2017

I have changed mind : getViewStateObservable() has public visibility in upcoming 3.0 release.

Mainly for unit testing reasons: now you can simply write unit tests for presenter by accessing the presenters observable which makes unit testing more convenient.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Model-View-Intent(MVI) in Android - Novatec Consulting GmbH
Presenter. Using RxJava the intents get wrapped in an observable which is then subscribed on to react to events emitted by the View....
Read more >
Mosby MVI: Inconsistent intent binding behavior - Stack Overflow
intentLoadData() doesn't emit a new item and the MviBasePresenter will provide the previous ViewState using the internal BehaviorSubject. My ...
Read more >
My take on Model View Intent (MVI) — Part 1: State Renderer
StateRenderer —exposes a single function that accepts an instance of ViewState and can render it to the Ui . This single point of...
Read more >
Reactive Apps with Model-View-Intent - Part 2
Model-View-Intent MVI on Android by using Mosby 3. Focusing on View and Intnet in this post.
Read more >
MVI at Playtomic - Angel G. Olloqui
open class BaseMVIPresenter<S: ViewState, A: ViewAction> { public var ... get() = viewState.value!! val viewState: Observable<ViewState> fun ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found