Skip to content

Instantly share code, notes, and snippets.

@cbedoy
Created March 24, 2021 18:22
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/1372c1738dcddcce85907c79f8daaab5 to your computer and use it in GitHub Desktop.
Save cbedoy/1372c1738dcddcce85907c79f8daaab5 to your computer and use it in GitHub Desktop.
class NewServiceViewModel(
private val useCase: NewServiceUseCase
): ViewModel {
private val _state: MutableStateFLow<NewServiceState>(NewServiceState.IldeState)
val state: StateFlow<NewServiceState> get() = _cart
suspend fun handleIntents(intent: NewServiceIntent){
when(intent){
is LoadProductsIntent -> {
useCase.loadProducts.collect { newState ->
_state.value = newState
}
}
is LoadProductsIntent -> {
useCase.addProduct(newProduct = intent.product).collect { newState ->
_state.value = newState
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment