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

UseCases not posting to UI by default #35

Open
minafkamel opened this issue Jun 11, 2018 · 1 comment
Open

UseCases not posting to UI by default #35

minafkamel opened this issue Jun 11, 2018 · 1 comment

Comments

@minafkamel
Copy link

minafkamel commented Jun 11, 2018

What if a UseCase (interactor) is not meant to post (just) to UI?

Assume we have to add a GetMoviesNames interactor that returns only names. It makes sense that it would use the existing GetMovies interactor and then apply more logic to the result to get the list of names only. How would this be achieved with GetMovies only posting to UI? Is there a way to make posting to UI optional so that UseCases could be consumed by other UseCases in different thread than UI?

@AppGrade-D
Copy link

Hello,
For now a UseCase class <Domain layer>decide on which thread work is done.
It is good to seperate thread logic from View Model <Presentation layer> and let UseCase do it by yourself.

But in the other hand we have a few cases when we can do simple optymalization by delegate work to other thread, for example please take a look at MoviesViewModel class:

private fun handleMovieList(movies: List<Movie>) { this.movies.value = movies.map { MovieView(it.id, it.poster) } }
this function receives list of Movie object and this function is responsible for mapping it to MovieView, in for each loop we are creating new MovieView object for every received item. In my opinion MoviesViewModel should take care about threading, becouse it is bridge between Presentation Layer and DomainLayer, in this case Domain Layer does not know about UI thread and Presentation Layer decides on which thread it want to handle result and all necessary mapping could be done on worker thread. In this model, ViewModel-s can easily merge a few UseCase-s or UseCase can merge other UseCase-s with no worries about threading.

This is only my opinion based on my expirience, I have used MVP with RxJava a lot in my projects and in my casses threading was done a moment before subscribing to Observable in Presenter layer. Beacouse Presenter is connection between View <---> Domain, it have all necessary knowledge about which operation should be done on which thread.

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

No branches or pull requests

3 participants