Skip to content
Discussion options

You must be logged in to vote

Hi @sbeitzel, the example code shows one way of debouncing where it is possible to offload the majority of work onto SwiftUI's task(id:) view modifier rather than re-creating it in the reducer. If you do not want to follow that pattern you can still perform a debounce that is similar to the old style. Just perform a sleep before executing the effect and then make the effect cancellable:

 private func updatePerson(state: State,
                           person: Person?) -> Effect<Action, Never> {
     let user = state.user
     if let person = person {
         return .task {
+            try await mainQueue.sleep(for: .seconds(1))
             return await .updated(
                 Task…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sbeitzel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants