@@ -13,7 +13,7 @@ import kotlinx.coroutines.async
1313import kotlinx.coroutines.awaitAll
1414import kotlinx.coroutines.cancelAndJoin
1515import kotlinx.coroutines.flow.MutableStateFlow
16- import kotlinx.coroutines.flow.asStateFlow
16+ import kotlinx.coroutines.flow.StateFlow
1717import kotlinx.coroutines.flow.distinctUntilChanged
1818import kotlinx.coroutines.flow.distinctUntilChangedBy
1919import kotlinx.coroutines.flow.filter
@@ -32,8 +32,8 @@ class HomeViewModel @Inject constructor(
3232 authRepository : AuthRepository ,
3333) : ViewModel() {
3434
35- private val _uiState = MutableStateFlow ( HomeUiState ())
36- val uiState = _uiState .asStateFlow( )
35+ val uiState : StateFlow < HomeUiState >
36+ field = MutableStateFlow ( HomeUiState () )
3737
3838 private var refreshJob: Job ? = null
3939
@@ -59,7 +59,7 @@ class HomeViewModel @Inject constructor(
5959 viewModelScope.launch {
6060 refreshJob?.cancelAndJoin()
6161 // Should after job cancellation since it will toggle it to false
62- _uiState .update { it.copy(isLoading = true ) }
62+ uiState .update { it.copy(isLoading = true ) }
6363 refreshJob = viewModelScope
6464 .launch {
6565 val jobs = enabledTrendingTypes.map {
@@ -70,13 +70,13 @@ class HomeViewModel @Inject constructor(
7070 .map { Entry (it) }
7171 }
7272 }
73- _uiState .update {
73+ uiState .update {
7474 it.copy(
7575 data = enabledTrendingTypes.zip(jobs.awaitAll()).toMap(),
7676 )
7777 }
7878 }.apply {
79- invokeOnCompletion { _uiState .update { it.copy(isLoading = false ) } }
79+ invokeOnCompletion { uiState .update { it.copy(isLoading = false ) } }
8080 }
8181 }
8282 }
0 commit comments