Skip to content
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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open

7주차 세미나 필수과제 #12

wants to merge 8 commits into from

Conversation

Eonji-sw
Copy link
Member

@Eonji-sw Eonji-sw commented Dec 6, 2023

📌𝘐𝘴𝘴𝘶𝘦𝘴

  • 7주차 필수 과제 구현
  • (StateFlow 구현)

📎𝘞𝘰𝘳𝘬 𝘋𝘦𝘴𝘤𝘳𝘪𝘱𝘵𝘪𝘰𝘯

  • UI 이벤트 및 상태 처리 StateFlow로 Handling

📷𝘚𝘤𝘳𝘦𝘦𝘯𝘴𝘩𝘰𝘵

device-2023-12-07-013803.mp4

💬𝘛𝘰 𝘙𝘦𝘷𝘪𝘦𝘸𝘦𝘳𝘴

안드 팟짱 태희오빠 너무 수고 많았어~
고생한 안봉이들도 모두모두 수고 많았어!!!

@Eonji-sw Eonji-sw added the essential 세미나 필수 과제 label Dec 6, 2023
@Eonji-sw Eonji-sw self-assigned this Dec 6, 2023
Comment on lines +14 to +15
private val _signUpState = MutableStateFlow<SignUpState>(SignUpState.Loading)
val signUpState: StateFlow<SignUpState> = _signUpState.asStateFlow()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sharedFlow가 아닌 stateFlow를 사용한 이유는 무엇일까요~?

Copy link

@sohyun127 sohyun127 left a 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()!!)

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 ->
Copy link

@sohyun127 sohyun127 Jan 3, 2024

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 중지시켜주어야해요!)

Comment on lines +5 to +9
sealed class UserState {
object Loading : UserState()
data class Success(val data: ResponseUserListDto) : UserState()
object Error : UserState()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 만들어진 코드만 보았을 때는 LoginState, SignUpState, UserState에서 처리하는 상태들이 동일합니다!
통합해서 관리하는 방법도 있지 않을까요?

Comment on lines +20 to 22
if (it.body() != null) {
_userState.value = UserState.Success(it.body()!!)
}

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 타입 체크를 해보면 좋을 것 같습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
essential 세미나 필수 과제
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants