-
Say you have a split view in a Mac app where both views have the ability to open a sheet. A naive, simplified example might look like this: struct Parent: ReducerProtocol {
struct State {
var child1: Child1.State
var child2: Child2.State
}
enum Action {
case child1 (Child1.Action)
case child2 (Child2.Action)
}
var body: some ReducerProtocol<State, Action> {
Scope(state: \.child1, action: /Action.child1) {
Child1()
}
Scope(state: \.child2, action: /Action.child2) {
Child2()
}
}
}
struct Child1: ReducerProtocol {
struct State {
var sheetIsPresented: Bool
}
enum Action {
case detailButtonTapped
case sheetDismissed
}
var body: some ReducerProtocol<State, Action> {
Reduce { state, action in
// ...
}
}
}
struct Child2: ReducerProtocol {
// ... mirrors Child1
} The problem is that I suppose you could intercept the actions of the children within the Is there a recommended approach to handling this coordination problem? I've been through the previous and recent navigation episodes, searched the forums, and looked through the in-progress work on the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @seanmrich, if I understand correctly, it seems that the child features should not each have their own navigation state. As you mentioned, that allows for invalid states. Instead, the navigation state should be coalesced into the parent as a single piece of state. An enum would be great for this: struct State {
var destination: Destination?
}
enum Destination {
case child1Sheet(Sheet.State)
case child2Sheet(Sheet.State)
} Technically, TCA has all the tools to accomplish this, they just aren't very ergonomic right now. The brand new navigation APIs we are working on will make this much nicer. I would say give that domain modeling a shot and let us know if you have any questions. There have also been a few discussions about this topic, such as this one. |
Beta Was this translation helpful? Give feedback.
Hi @seanmrich, if I understand correctly, it seems that the child features should not each have their own navigation state. As you mentioned, that allows for invalid states.
Instead, the navigation state should be coalesced into the parent as a single piece of state. An enum would be great for this:
Technically, TCA has all the tools to accomplish this, they just aren't very ergonomic right now. The brand new navigation APIs we are working on will make this much nicer.
I would say give that domain modeling a shot and let us know if you have any questions. T…