Skip to content

Instantly share code, notes, and snippets.

@cbedoy
Created March 24, 2021 18:12
Show Gist options
  • Select an option

  • Save cbedoy/7ae48ad7ccb958bd4d64a374802ba90f to your computer and use it in GitHub Desktop.

Select an option

Save cbedoy/7ae48ad7ccb958bd4d64a374802ba90f to your computer and use it in GitHub Desktop.
class NewServiceViewModel(
private val useCase: NewServiceUseCase
): ViewModel {
private val _cart: MutableLiveData<List<Product>>
val cart: LiveData<List<Product>> get() = _cart
private val _products: MutableLiveData<List<Product>>
val products: LiveData<List<Product>> get() = _products
private val _showLoader: MutableLiveData<Boolean>
val showLoader: LiveData<Boolean>> get() = _showLoader
suspend fun loadProducts(){
_showLoader.post(true)
_products.post(useCase.prepareProducts())
_showLoader.post(false)
}
suspend fun addProduct(product: Product){
_card.post(useCase.addProduct(product))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment