Created
August 23, 2022 11:08
-
-
Save DenisBronx/b130ce1decaf2004b42d0c9efec18f0f to your computer and use it in GitHub Desktop.
Avoid Use Case Boilerplate Approach 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class SomeModel(val id: String, val name: String) | |
interface SomeModelRepository { | |
suspend fun getSomeModels(): Answer<List<SomeModel>, String> | |
} | |
fun interface GetSomeModelUseCase : suspend () -> Answer<List<SomeModel>, String> | |
class SomeViewModel(private val getSomeModelUseCase: GetSomeModelUseCase) : ViewModel() { | |
fun load() { | |
viewModelScope.launch { | |
val result = getSomeModelUseCase() | |
// Do something with the result | |
} | |
} | |
} | |
fun provideViewModel(someModelRepository: SomeModelRepository): SomeViewModel { | |
return SomeViewModel(someModelRepository::getSomeModels) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment