-
I am not sure how to handle properties of type enum with multiple Associated values in struct State. For example, assume that the following List Feature and the Row corresponding to each item are defined. struct ListFeature: ReducerProtocol {
struct State: Equatable {
enum EnumState: Equatable {
case notLoaded
case loaded(rows: IdentifiedArrayOf<Row.State>, pageInfo: PageInfo)
}
var enumState: EnumState
}
enum Action {
case row(id: Row.State.ID, action: Row.Action)
}
var body: some ReducerProtocol<State, Action> {
// No Idea...
}
} In this case, I don't know what to do if I want to scope enumState, a State property, according to its state change. I have tried the following link, but in the end I want to focus only on the rows of the associated value. var body: some ReducerProtocol<State, Action> {
Scope(state: \.enumState, action: /.self) {
Scope(state: /State.EnumState.loaded(rows:pageInfo:), action: /.self) {
Scope(state: ????, action: /.self) { // ← How write with state ?
EmptyReducer()
.forEach(\.self, action: /Action.row(id:action:)) {
Row()
}
}
}
}
Reduce { state, action in
// some pattern matching code
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Technically I think it would work to do |
Beta Was this translation helpful? Give feedback.
Technically I think it would work to do
\.0
to key path into the first component of the tuple of theloaded
associated value. Even\.rows
might work. But it would probably be better to bundle uprows
andpageInfo
into their own struct, and then just hold onto that inEnumState.loaded
.