Last active
March 24, 2021 22:50
-
-
Save cbedoy/3ba55fb7decdb8562a6ec1ad49dcbd57 to your computer and use it in GitHub Desktop.
ViewModel + MVI + Flow
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
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