android10 / android10/Android-CleanArchitecture
Transforming to presentation model is done on UI thread, because of UseCase limitations
- Lingua principale
- Java
- Stelle
- 15.5k
- Fork
- 3.3k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
In your code, you transform `domain` entities into `presentation` model in UI thread, mainly because the `UseCase` can't access entities from `presentation`.
E.g. [UserDetailsPresenter.java#L100](https://github.com/android10/Android-CleanArchitecture/blob/master/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/UserDetailsPresenter.java#L100), [UserListPresenter.java#L109](https://github.com/android10/Android-CleanArchitecture/blob/master/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/presenter/UserListPresenter.java#L109)
Transformations in UI thread is not a really good idea, especially when we have the power of `RxJava.`
So, in my projects, a UseCase is an interface like this
```kotlin
interface UseCase {
fun buildUseCaseObservable(params: Params): Observable
}
```
Mainly because I have the following cases. Here, I want to transform some data from repository model into `presentation` model, but I don't want to do it on UI thread, and I don't want to start another async procedure, or lose convenience of Rx transformation methods, so I apply transformations for the use case observable in my presenter.
```kotlin
disposable = useCase.buildUseCaseObservable(Unit)
.subscribeOn(schedulers.io())
.map { SectionedVideoListMapper.transform(it) }
.observeOn(schedulers.mainThread())
.subscribe(this::onDataLoaded, this::onDataLoadFailed)
```
Or here, I cannot pass Intent to `domain` layer to retrieve the video list, so I do this transformation off UI thread before passing it to `UseCase`.
```kotlin
Observable.fromCallable { PlaylistVideoMapper.transform(contentResolver, data) }
.subscribeOn(schedulers.io())
.flatMap { useCase.buildUseCaseObservable(CreatePlaylistUseCase.Params(name, it)) }
.observeOn(schedulers.mainThread())
.subscribe({}, this::onPlaylistCreateFailed)
```
What do you think about this approach?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Inizia dalle posizioni indicate nell’issue in UserDetailsPresenter.java e UserListPresenter.java, quindi segui il confine di UseCase e le catene RxJava descritte nell’issue. L’issue richiede un parere architetturale invece di indicare una modifica concreta, quindi per completarla sarebbe necessaria una decisione di un maintainer sull’approccio proposto prima di poter definire l’ambito dell’implementazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- android, java
- Ambito
- mobile
- Tipo di issue
- Refactoring
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 20/100