-
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
feature:notifications 생성 #318
feature:notifications 생성 #318
Conversation
pagingSourceFactory = { NotificationPagingSource(api) }, | ||
).flow.map { it.map { it.toExternalModel() } } | ||
} |
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.
일단 옮겨온 Repository에서는
Flow<PagingData<NotificationDto>>
가 아니라 Flow<PagingData<Notification>>
을 내려주도록 바꿨다.
|
||
fun getNotifications() { | ||
viewModelScope.launch { | ||
notificationRepository.getNotificationResultStream() | ||
.cachedIn(viewModelScope) | ||
.collect { | ||
_notificationList.emit(it) | ||
} | ||
} | ||
} | ||
} |
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.
이거 원래 init이었는데
일단 일반함수로 바꾸고 뷰에서 LaunchedEffect로 실행
|
||
val notificationsUiState: StateFlow<NotificationsUiState> = | ||
notificationList | ||
.map<PagingData<Notification>, NotificationsUiState>(NotificationsUiState::Success) | ||
.onStart { emit(NotificationsUiState.Loading) } | ||
.catch { emit(NotificationsUiState.Error) } | ||
.stateIn( | ||
scope = viewModelScope, | ||
started = SharingStarted.WhileSubscribed(5_000), | ||
initialValue = NotificationsUiState.Loading, | ||
) | ||
|
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.
위의 함수가 실행되면 notificationList가 바뀌어서 notificationUiState도 바뀌게 되는데...
|
||
sealed interface NotificationsUiState { | ||
data object Loading : NotificationsUiState | ||
|
||
data object Error : NotificationsUiState | ||
|
||
data class Success( | ||
val notifications: PagingData<Notification>, | ||
) : NotificationsUiState | ||
} |
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.
NotificationsUiState는 이렇게 정의해봤어 NIA도 비슷하게 되어있어서
notificationList | ||
.map<PagingData<Notification>, NotificationsUiState>(NotificationsUiState::Success) | ||
.onStart { emit(NotificationsUiState.Loading) } | ||
.catch { emit(NotificationsUiState.Error) } | ||
.stateIn( |
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.
상황에 따라 Loading, Error로 적절하게 들어갈 수 있고,
정상적으로 불러올 경우 NotificationUiState.Success로 감싸서 내려주게 되는데...
문제는 Success의 경우 Notifications가 PagingData<Notification>
이라서 (StateFlow가 아니라는게 문제!)
val notifications = notificationsUiState.notifications | ||
items(notifications) { | ||
it?.let { |
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.
여기서 갖다 쓸수가 없다... (items에 넣을 수가 없음)
원래는 StateFlow<PagingData<Notification>>
를 collectAsLazyPagingItems해서 할수 있었는데
지금은 방법이 없다... NIA에서 이 방식이 가능했던 이유는
NotificationsUiState.Success가 List를 담기 때문이다.
이거 어떻게 해야 할까...
No description provided.