Last active
March 7, 2022 20:30
-
-
Save MessiasLima/8956d82aef89651aa682be73a695c384 to your computer and use it in GitHub Desktop.
SplashViewModelBefore
This file contains hidden or 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
import androidx.lifecycle.ViewModel | |
import com.messiaslima.promogamer.domain.Store | |
import kotlinx.coroutines.flow.catch | |
import kotlinx.coroutines.flow.map | |
import kotlinx.coroutines.flow.onStart | |
class StoreViewModel(private val storeOrchestrator: StoreOrchestrator) : ViewModel() { | |
val uiState = storeOrchestrator.getStores() | |
.map<List<Store>, UiState> { UiState.Success(it) } | |
.catch { throwable -> emit(UiState.Error(throwable)) } | |
.onStart { emit(UiState.Loading) } | |
sealed class UiState { | |
object Loading : UiState() | |
class Success(stores: List<Store>) : UiState() | |
class Error(throwable: Throwable) : UiState() | |
object Idle : UiState() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment