Skip to content
Discussion options

You must be logged in to vote

Turns out that I had not understood the reasoning behind popFrom(id:) at all...
The following solution was brought to me in the project's Slack by Marius K. In the parent's reducer, I can listen to popFrom(id:) and sync changes back on dismissal of the child like this:

case .path(.popFrom(id: let id)):
        guard let childState = state.path[id: id]?.itemDetail
        else { return .none }
        let mutatingItem = childState.mutatingItem
        if let index = state.items.firstIndex(where: {  $0.id == mutatingItem.id }) {
          state.items[index] = mutatingItem
        }
        return .none

For completeness sake, here's the entire code:

import ComposableArchitecture
import Swift…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by appfrosch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant