Skip to content

Instantly share code, notes, and snippets.

@cbedoy
Last active March 24, 2021 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbedoy/3ba55fb7decdb8562a6ec1ad49dcbd57 to your computer and use it in GitHub Desktop.
Save cbedoy/3ba55fb7decdb8562a6ec1ad49dcbd57 to your computer and use it in GitHub Desktop.
ViewModel + MVI + Flow
class NewServiceViewModel2 (
private val useCase: NewServiceUseCase) : BaseMVIViewModel<NewServiceState, NewServiceIntent>(
initialState = NewServiceState.IldeState
) {
override val TAG: String
get() = "NewServiceViewModel"
override suspend fun onCollect(intent: NewServiceIntent, producer: suspend (Flow<NewServiceState>) -> Unit) {
when(intent){
is NewServiceIntent.LoadProducts -> {
producer(useCase.loadProducts)
}
is NewServiceIntent.AddProduct -> {
producer(useCase.addProduct(state.product))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment