Skip to content

Commit 3fe2b8c

Browse files
committed
refactor: 삭제 후 fetch하도록 개선
1 parent ca694c6 commit 3fe2b8c

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

DevLog/Presentation/ViewModel/PushNotificationListViewModel.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,17 @@ final class PushNotificationListViewModel: Store {
157157
}
158158
case .undoDelete(let notificationId):
159159
Task {
160+
// defer을 통해 setLoading을 false로 제어하지 않는 이유
161+
// send(.fetchNotifications)를 통해 false로 처리될 것이기 때문
162+
send(.setLoading(true))
163+
160164
do {
161165
try await undoDeleteUseCase.execute(notificationId)
162-
send(.fetchNotifications)
163166
} catch {
164167
send(.setAlert(isPresented: true))
165-
send(.fetchNotifications)
166168
}
169+
170+
send(.fetchNotifications)
167171
}
168172
case .toggleRead(let notificationId):
169173
Task {

DevLog/Presentation/ViewModel/TodoListViewModel.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ final class TodoListViewModel: Store {
137137
return effects
138138
}
139139

140+
// swiftlint:disable function_body_length
140141
func run(_ effect: SideEffect) {
141142
switch effect {
142143
case .fetch:
@@ -230,15 +231,21 @@ final class TodoListViewModel: Store {
230231
}
231232
case .undoDelete(let todoId):
232233
Task {
234+
// defer을 통해 setLoading을 false로 제어하지 않는 이유
235+
// send(.refresh)를 통해 false로 처리될 것이기 때문
236+
send(.setLoading(true))
237+
233238
do {
234239
try await undoDeleteTodoUseCase.execute(todoId)
235-
send(.refresh)
236240
} catch {
237-
send(.setAlert(true)); send(.refresh)
241+
send(.setAlert(true))
238242
}
243+
244+
send(.refresh)
239245
}
240246
}
241247
}
248+
// swiftlint:enable function_body_length
242249
}
243250

244251
// MARK: - Reduce Methods

0 commit comments

Comments
 (0)