Skip to content

Commit ffe3495

Browse files
stephencelismluisbrown
authored andcommitted
Fix Recursive Reducer (#267)
1 parent 5324a5b commit ffe3495

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Examples/CaseStudies/SwiftUICaseStudies/04-HigherOrderReducers-Recursion.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct NestedState: Equatable, Identifiable {
3434

3535
indirect enum NestedAction: Equatable {
3636
case append
37+
case exclaim
3738
case node(index: Int, action: NestedAction)
3839
case remove(IndexSet)
3940
case rename(String)
@@ -51,16 +52,24 @@ let nestedReducer = Reducer<
5152
state.children.append(NestedState(id: environment.uuid()))
5253
return .none
5354

55+
case .exclaim:
56+
state.description += "!"
57+
return .none
58+
5459
case let .node(index, action):
5560
return self.run(&state.children[index], action, environment)
61+
.map { .node(index: index, action: $0) }
5662

5763
case let .remove(indexSet):
5864
state.children.remove(atOffsets: indexSet)
5965
return .none
6066

6167
case let .rename(name):
68+
struct ExclaimId: Hashable {}
69+
6270
state.description = name
63-
return .none
71+
return Effect(value: .exclaim)
72+
.debounce(id: ExclaimId(), for: 1, scheduler: DispatchQueue.main)
6473
}
6574
}
6675

0 commit comments

Comments
 (0)