Skip to content
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

Fix Recursive Reducer #267

Merged
merged 1 commit into from
Aug 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct NestedState: Equatable, Identifiable {

indirect enum NestedAction: Equatable {
case append
case exclaim
case node(index: Int, action: NestedAction)
case remove(IndexSet)
case rename(String)
Expand All @@ -51,16 +52,24 @@ let nestedReducer = Reducer<
state.children.append(NestedState(id: environment.uuid()))
return .none

case .exclaim:
state.description += "!"
return .none

case let .node(index, action):
return self.run(&state.children[index], action, environment)
.map { .node(index: index, action: $0) }

case let .remove(indexSet):
state.children.remove(atOffsets: indexSet)
return .none

case let .rename(name):
struct ExclaimId: Hashable {}

state.description = name
return .none
return Effect(value: .exclaim)
.debounce(id: ExclaimId(), for: 1, scheduler: DispatchQueue.main)
}
}

Expand Down