Skip to content

Commit

Permalink
Alterei o lifecycle do flow da lista de bolas
Browse files Browse the repository at this point in the history
  • Loading branch information
MuriTG25 committed Dec 11, 2023
1 parent d8aa924 commit 0921aa8
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import br.com.alura.mundobola.aplicacao.repositorio.MundoBolaRepositorio
import br.com.alura.mundobola.ui.stateholder.ListaDeBolasUiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand All @@ -29,6 +31,11 @@ class ListaDeBolasViewModel @Inject constructor(

private suspend fun carregaLista() {
repositorio.listaDeBolas()
.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5000),
emptyList()
)
.collect { lista ->
_uiState.value = _uiState.value.copy(
listaDeBolas = lista.map {
Expand Down

0 comments on commit 0921aa8

Please sign in to comment.