Skip to content

Instantly share code, notes, and snippets.

@cbedoy
Last active March 24, 2021 18:31
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/c4a1677d912a997bb1463735ce988cbc to your computer and use it in GitHub Desktop.
Save cbedoy/c4a1677d912a997bb1463735ce988cbc to your computer and use it in GitHub Desktop.
class NewServiceUseCase(
private val repository: NewServiceRepository
){
val loadProducts = flow {
emit(ShowLoader)
when(val response = repository.loadProducts){
is Success -> {
emit(ReloadProducts(response.preparedProducts))
}
else -> {
emit(ReloadProducts(emptyList()))
}
}
emit(HideLoader)
emit(Ilde)
}
fun addProduct(product: Product) = flow {
emit(CartStorage(currentCartStorage.add(product)))
emit(Ilde)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment