RIBs icon indicating copy to clipboard operation
RIBs copied to clipboard

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

Open ericntd opened this issue 4 years ago • 3 comments

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) {
}

ericntd avatar Mar 22 '21 19:03 ericntd

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

andreasnomikos avatar Jun 22 '21 15:06 andreasnomikos

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

ericntd avatar Jun 22 '21 17:06 ericntd

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

J909 avatar Aug 14 '21 05:08 J909