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
import androidx.lifecycle.ViewModel | |
import com.messiaslima.promogamer.domain.Store | |
import kotlinx.coroutines.FlowPreview | |
import kotlinx.coroutines.flow.catch | |
import kotlinx.coroutines.flow.map | |
import kotlinx.coroutines.flow.onStart | |
@FlowPreview | |
class StoreViewModel(private val storeOrchestrator: StoreOrchestrator) : ViewModel() { | |
private val retryTrigger = RetryTrigger() |
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
import kotlinx.coroutines.FlowPreview | |
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.filter | |
import kotlinx.coroutines.flow.flatMapConcat | |
import kotlinx.coroutines.flow.onEach | |
@FlowPreview | |
fun <T> retryableFlow(retryTrigger: RetryTrigger, flowProvider: () -> Flow<T>) = | |
retryTrigger.retryEvent.filter { it == RetryTrigger.State.RETRYING } |
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
@Composable | |
fun SampleComposable(viewModel: StoreViewModel = viewModel()){ | |
val uiState by viewModel.uiState.collectAsState(initial = UiState.Idle) | |
// Some nice composables here | |
} |
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
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) } |