Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To keep the state in Presenter or Interactor for click events? #411

Open
ericntd opened this issue Mar 22, 2021 · 3 comments
Open

To keep the state in Presenter or Interactor for click events? #411

ericntd opened this issue Mar 22, 2021 · 3 comments
Labels
Android Android related tickets

Comments

@ericntd
Copy link

ericntd commented Mar 22, 2021

I'd prefer to keep things stateless if possible
A Stream is perfect for that but too much work
So keeping the state for click events
But can't make up my mind between the Interactor and the Presenter
Any recommendations?

A typical Interactor:

override fun didBecomeActive() {
        super.didBecomeActive()
        getDataAsync()
               .subscribe { theData ->
                       // to keep theData as state here or not?
                       presenter.present(theData) // or inside the Presenter? 🤔 
               }
}

// upon user click, we need to theData again
fun onClick(theData: TheDataType) {
}
@andreasnomikos
Copy link

Actually to better utilize unidirectional data flow you should not make the presenter api imperative.

Loading your asyncData to a state store like https://reduxkotlin.org/ is a better option then you can monitor that into the presenter usually after transforming it first to a viewmodel.
If you follow the clean architecture paradigm this looks as such

Usecases load DTOs -> Interactor stores Entities (ReduxStore) -> Presenter renders ViewModels

@ericntd
Copy link
Author

ericntd commented Jun 22, 2021

My previous teams migrated away from event bus into Reactive programming (with RxJava) for good reasons. So redux is a thanks but no thanks

@jbarr21 jbarr21 added the Android Android related tickets label Jul 9, 2021
@J909
Copy link

J909 commented Aug 14, 2021

In case getDataAsync() were to cache the last emission e.g. with replay(1), you could getDataAsync().take(1) in your onClick() callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Android related tickets
Projects
None yet
Development

No branches or pull requests

4 participants