-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: ViewModel의 LiveData를 Flow로 변경 #695
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다 해음
retrofit, repository도 flow로 바꾸자는 말을 했었는데,
대부분 한 번에 하나의 값을 불러오는 요청들이네요.
구독을 해놓고 연속적으로 값을 여러 번 읽어야 하는 상황이 아닌 이상 flow를 쓰는 건 의미가 없을 것 같습니다.
그냥 suspend인 채로 둬도 될 것 같아요.
@@ -13,11 +10,17 @@ import com.mulberry.ody.presentation.address.listener.AddressListener | |||
import com.mulberry.ody.presentation.address.model.AddressUiModel | |||
import com.mulberry.ody.presentation.address.model.toAddressUiModels | |||
import com.mulberry.ody.presentation.common.BaseViewModel | |||
import com.mulberry.ody.presentation.common.MutableSingleLiveData | |||
import com.mulberry.ody.presentation.common.SingleLiveData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SingleLiveData야 고생 많았다
} | ||
} | ||
|
||
fun withdrawAccount() { | ||
viewModelScope.launch { | ||
startLoading() | ||
loginRepository.withdrawAccount() | ||
.onSuccess { | ||
_loginNavigateEvent.setValue(LoginNavigatedReason.WITHDRAWAL) | ||
.suspendOnSuccess { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suspendOnSuccess가 여기에 필요한 거였나요 😮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞습둥
val hasAddressSearchKeyword: StateFlow<Boolean> = | ||
addressSearchKeyword.map { it.isNotEmpty() }.stateIn( | ||
scope = viewModelScope, | ||
started = SharingStarted.WhileSubscribed(5000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configuration change 대응 코드인가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨어요 해음 Flow 고수다 이제~!
val navigatedReason: SingleLiveData<LoginNavigatedReason> get() = _navigatedReason | ||
private val _navigatedReason: MutableSharedFlow<LoginNavigatedReason> = | ||
MutableSharedFlow() | ||
val navigatedReason: SharedFlow<LoginNavigatedReason> get() = _navigatedReason.asSharedFlow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val navigatedReason: SharedFlow<LoginNavigatedReason> get() = _navigatedReason.asSharedFlow() | |
val navigatedReason: SharedFlow<LoginNavigatedReason> get() = _navigatedReason |
asSharedFlow()
가 없어도 SharedFlow
로 형변환되는 걸로 알고 있는데 명시해준 이유가 있을까요?
val actual = viewModel.isValidInfo.getOrAwaitValue() | ||
assertThat(actual).isTrue | ||
val actual = viewModel.isValidInfo.value | ||
assertThat(actual).isTrue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른 테스트에서는 괄호 없이 isTrue
, isFalse
로만 사용하고 있는데 여기도 통일성을 위해 괄호빼면 어떨까요?
@@ -159,11 +158,11 @@ class MeetingCreationViewModelTest { | |||
|
|||
// when | |||
viewModel.meetingDate.value = LocalDate.of(2023, 7, 28) | |||
viewModel.meetingHour.value = 18 | |||
viewModel.meetingHour.value = 17 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
왜 18에서 17으로 바뀐 건가요??
@@ -109,7 +119,7 @@ class MeetingCreationViewModel | |||
} | |||
|
|||
private fun createMeetingCreationInfo(): MeetingCreationInfo? { | |||
val name = meetingName.value ?: return null | |||
val name = meetingName.value.takeIf { it.isNotEmpty() } ?: return null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val name = meetingName.value.takeIf { it.isNotEmpty() } ?: return null | |
val name = meetingName.value.ifBlank { return null } |
이렇게 변경하면 더 직관적이지 않을까요?
val meetingHour = MutableStateFlow<Int?>(null) | ||
val meetingMinute = MutableStateFlow<Int?>(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullable 타입은 최대한 지양하면 좋을 것 같은데 createMeetingCreationInfo()
에서 null인 경우 return하기 위해서 이렇게 작성하신 건가요??
val meetingHour = MutableStateFlow<Int?>(null) | |
val meetingMinute = MutableStateFlow<Int?>(null) | |
val meetingHour = MutableStateFlow<Int>(-1) | |
val meetingMinute = MutableStateFlow<Int>(-1) |
이렇게 변경하고 createMeetingCreationInfo()
에서 -1인지 검사하면 어떨까요? _inviteCode
등 다른 프로퍼티도 마찬가지입니다~
val isEmptyAddresses: StateFlow<Boolean> = | ||
addresses.map { it.isEmpty() }.stateIn( | ||
scope = viewModelScope, | ||
started = SharingStarted.WhileSubscribed(5000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5000 상수로 빼면 어떨까요?? 다른 ViewModel도 마찬가지입니다!!
🚩 연관 이슈
close #640
📝 작업 내용
🏞️ 스크린샷 (선택)
🗣️ 리뷰 요구사항 (선택)
Flow로 다 마이그레이션 하면 MutableSingleLiveData 지워야 합니다!