-
Notifications
You must be signed in to change notification settings - Fork 0
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
7주차 세미나 필수과제 #12
base: develop
Are you sure you want to change the base?
7주차 세미나 필수과제 #12
Conversation
# Conflicts: # app/src/main/java/org/sopt/dosopttemplate/presentation/auth/login/LoginViewModel.kt
private val _signUpState = MutableStateFlow<SignUpState>(SignUpState.Loading) | ||
val signUpState: StateFlow<SignUpState> = _signUpState.asStateFlow() |
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.
sharedFlow가 아닌 stateFlow를 사용한 이유는 무엇일까요~?
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.
먼지 화이팅!!!!!
|
||
fun signUp(id: String, name: String, password: String) { | ||
viewModelScope.launch { | ||
kotlin.runCatching { | ||
authService.signUp(RequestSignUpDto(id, name, password)) | ||
}.onSuccess { | ||
signUpSuccess.value = it.isSuccessful | ||
_signUpState.value = SignUpState.Success(it.body()!!) |
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.
!!(Non-null assertion operator)를 사용하신 이유는 무엇인가요?!
현재 it.body()에 null값이 들어오면 NullPointerException을 발생하는데요, !!(Non-null assertion operator)을 사용하지 않고 null 타입 체크를 해보면 좋을 것 같습니다!
|
||
userAdapter.setUserList(userList) | ||
lifecycleScope.launch { | ||
userViewModel.userState.collect { userState -> |
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.
flowWithLifecycle에 대해서 공부해보면 좋을 것 같아요!
(힌트는 StateFlow는 lifecycle을 자동으로 처리하지 않아서 수동으로 flow의 collect 중지시켜주어야해요!)
sealed class UserState { | ||
object Loading : UserState() | ||
data class Success(val data: ResponseUserListDto) : UserState() | ||
object Error : UserState() | ||
} |
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.
현재 만들어진 코드만 보았을 때는 LoginState, SignUpState, UserState에서 처리하는 상태들이 동일합니다!
통합해서 관리하는 방법도 있지 않을까요?
if (it.body() != null) { | ||
_userState.value = UserState.Success(it.body()!!) | ||
} |
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.
null일 때의 분기 처리는 어딨죠?!
추가적으로
!!은 어떤 값이든 널이 될 수 없는 타입으로 (강제로) 바꾸는 단순하면서도 무딘 도구다.
라고 Kotlin in Action에서는 표현하였는데요!
위에서 설명했듯이 !!(Non-null assertion operator)를 사용하지 않고 null 타입 체크를 해보면 좋을 것 같습니다!
📌𝘐𝘴𝘴𝘶𝘦𝘴
📎𝘞𝘰𝘳𝘬 𝘋𝘦𝘴𝘤𝘳𝘪𝘱𝘵𝘪𝘰𝘯
📷𝘚𝘤𝘳𝘦𝘦𝘯𝘴𝘩𝘰𝘵
device-2023-12-07-013803.mp4
💬𝘛𝘰 𝘙𝘦𝘷𝘪𝘦𝘸𝘦𝘳𝘴
안드 팟짱 태희오빠 너무 수고 많았어~
고생한 안봉이들도 모두모두 수고 많았어!!!