Skip to content

Commit 5d2e58c

Browse files
stephencelismluisbrown
authored andcommitted
Clean up Todos sort debouncing (#1255)
(cherry picked from commit 0f3175f96831d5bad24c7efda1f808637ffecb4d)
1 parent 32afd5e commit 5d2e58c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Examples/Todos/Todos/Todos.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ let appReducer = Reducer<AppState, AppAction, AppEnvironment>.combine(
9191

9292
case .todo(id: _, action: .checkBoxToggled):
9393
enum TodoCompletionID {}
94-
return .task { .sortCompletedTodos }
95-
.debounce(id: TodoCompletionID.self, for: 1, scheduler: environment.mainQueue.animation())
94+
return .task {
95+
try await environment.mainQueue.sleep(for: .seconds(1))
96+
return .sortCompletedTodos
97+
}
98+
.animation()
99+
.cancellable(id: TodoCompletionID.self, cancelInFlight: true)
96100

97101
case .todo:
98102
return .none
99103
}
100104
}
101105
)
102-
.debug()
103106

104107
struct AppView: View {
105108
let store: Store<AppState, AppAction>

Examples/Todos/Todos/TodosApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct TodosApp: App {
99
AppView(
1010
store: Store(
1111
initialState: AppState(),
12-
reducer: appReducer,
12+
reducer: appReducer.debug(),
1313
environment: AppEnvironment(
1414
mainQueue: QueueScheduler.main,
1515
uuid: { UUID() }

0 commit comments

Comments
 (0)