Replies: 1 comment 9 replies
-
@seanmrich Can you extend the @Reducer
enum Path {
typealias State = StatesModule.RootPathState
case child(Child)
}
extension Path.State: CaseReducerState {
typealias StateReducer = Path
} (You may need to move the extension to a separate file due to some macro bugs in Swift 5.9/10.) This should unlock the shorthand Alternately, you can do the longhand .forEach(\.path, action: \.path) {
Path.body
} |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I love the simplification of path reducers and associated
NavigationStack
destinations in v1.8. However, I've had some trouble integrating into an app. It relates to the issue of how a child feature can push a path element onto the stack. The child feature can't see thePath
state if it's defined in a separate module without importing the parent which causes a circular reference. From previous discussions, there are two recommendations to handling this:NavigationLink(state:label:)
in the child feature to push a new path element. To avoid circular references between the parent and child features, create a separate module that holds theState
types for the path and all associated child features.Button
instead ofNavigationLink
and send a delegate action requesting a new element for the path. The parent feature monitors for those delegate actions and manages theStackState
itself.I've been using the first method, and it isn't clear how to use the new 1.8 features to clean up the path reducer. Here's the shape of the existing type where
RootPathState
is declared in a separate moduleStatesModule
:If I want to pare this down using the new 1.8 hotness:
Much better 👍 and this compiles, but using it in the parent reducer raises an error because
Path.State
didn't get conformance toCaseReducerState
:It makes sense that the
@Reducer
macro doesn't fiddle with an explicitly declaredState
type, but otherwise using theNavigationLink
method described above doesn't seem possible. When using this sugared version of path declaration, is it necessary to useButton
s for pushing navigation elements?Beta Was this translation helpful? Give feedback.
All reactions