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.
sharedFlow가 아닌 stateFlow를 사용한 이유는 무엇일까요~?
| authService.signUp(RequestSignUpDto(id, name, password)) | ||
| }.onSuccess { | ||
| signUpSuccess.value = it.isSuccessful | ||
| _signUpState.value = SignUpState.Success(it.body()!!) |
There was a problem hiding this comment.
!!(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.
flowWithLifecycle에 대해서 공부해보면 좋을 것 같아요!
(힌트는 StateFlow는 lifecycle을 자동으로 처리하지 않아서 수동으로 flow의 collect 중지시켜주어야해요!)
| sealed class UserState { | ||
| object Loading : UserState() | ||
| data class Success(val data: ResponseUserListDto) : UserState() | ||
| object Error : UserState() | ||
| } No newline at end of file |
There was a problem hiding this comment.
현재 만들어진 코드만 보았을 때는 LoginState, SignUpState, UserState에서 처리하는 상태들이 동일합니다!
통합해서 관리하는 방법도 있지 않을까요?
| if (it.body() != null) { | ||
| _userState.value = UserState.Success(it.body()!!) | ||
| } |
There was a problem hiding this comment.
null일 때의 분기 처리는 어딨죠?!
추가적으로
!!은 어떤 값이든 널이 될 수 없는 타입으로 (강제로) 바꾸는 단순하면서도 무딘 도구다.
라고 Kotlin in Action에서는 표현하였는데요!
위에서 설명했듯이 !!(Non-null assertion operator)를 사용하지 않고 null 타입 체크를 해보면 좋을 것 같습니다!
📌𝘐𝘴𝘴𝘶𝘦𝘴
📎𝘞𝘰𝘳𝘬 𝘋𝘦𝘴𝘤𝘳𝘪𝘱𝘵𝘪𝘰𝘯
📷𝘚𝘤𝘳𝘦𝘦𝘯𝘴𝘩𝘰𝘵
device-2023-12-07-013803.mp4
💬𝘛𝘰 𝘙𝘦𝘷𝘪𝘦𝘸𝘦𝘳𝘴
안드 팟짱 태희오빠 너무 수고 많았어~
고생한 안봉이들도 모두모두 수고 많았어!!!