Replies: 1 comment
-
What I think could be the answer to my 2. question is what is explained here #3208 (comment) Let the case .path(.element(id: _, action: .contactDetails(.delegate(.didDeleteContact(let contact))))):
print("Delete \(contact)")
guard let listIndex = state.path.firstIndex(where: { $0.is(\.contactList) }) else { return .none }
state.path[id: state.path.ids[listIndex]].modify(\.contactList) { contactListState in
contactListState.removeContact(contact)
}
_ = state.path.popLast() That works for me even thought the syntax a bit cumbersome :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hey,
I have a stack based navigation where I don't use NavigationLinks but rather delegate actions sent from child views back to
the Root view where the entire navigation stack is handled.
Basically what is described in the stack-based navigation docs
The question is how can I intercept the
case .path(.element(id: _, action: ...))
in one of the child views in order to perform business logic belonging to that view instead of handling it in the root view.⬇️ Complete sample code ⬇️
The navigation is composed of
MyRootFeature
MyContactListFeature
andMyContactDetailFeature
screensMyContactListFeature
.addButtonTapped
locally to simply append a new contact to the list:.contactButtonTapped(contact)
, transforms it to a delegate action to be handled by the RootViewMyContactDetailFeature
I'd like to handle the deletion of the contact
.delegate(.didDeleteContact(state.contact)
in theMyContactListFeature
where I also handle the addition of a contact. But in the current implementation, the.delegate(.didDeleteContact(
is forwarded until theMyRootFeature
.Is it possible to intercept that
.delegate(.didDeleteContact(state.contact)
in theMyContactListFeature
?Alternatively, how could the
MyRootFeature
reach out to theMyContactListFeature.State
to tell it to delete the contact once the MyRootFeature has intercepted the.contactDetails(.delegate(.didDeleteContact(let contact)
?I tried
I know that I could handle the deletion in the RootView but I'd like the RootView to be responsible only of the navigation and not of the business logic of all the child views.
thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions