Skip to content

Commit

Permalink
refactor: asStateFlow, asSharedFlow 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyCh0 committed Oct 5, 2023
1 parent 81ea32a commit 0ca2bc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -21,10 +23,10 @@ class FestivalListViewModel @Inject constructor(
) : ViewModel() {

private val _uiState = MutableStateFlow<FestivalListUiState>(FestivalListUiState.Loading)
val uiState: StateFlow<FestivalListUiState> = _uiState
val uiState: StateFlow<FestivalListUiState> = _uiState.asStateFlow()

private val _event = MutableSharedFlow<FestivalListEvent>()
val event: SharedFlow<FestivalListEvent> = _event
val event: SharedFlow<FestivalListEvent> = _event.asSharedFlow()

fun loadFestivals() {
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -25,10 +27,10 @@ class MyPageViewModel @Inject constructor(
) : ViewModel() {

private val _uiState = MutableStateFlow<MyPageUiState>(MyPageUiState.Loading)
val uiState: StateFlow<MyPageUiState> = _uiState
val uiState: StateFlow<MyPageUiState> = _uiState.asStateFlow()

private val _event = MutableSharedFlow<MyPageEvent>()
val event: SharedFlow<MyPageEvent> = _event
val event: SharedFlow<MyPageEvent> = _event.asSharedFlow()

fun loadUserInfo() {
if (!authRepository.isSigned) {
Expand Down

0 comments on commit 0ca2bc8

Please sign in to comment.