I'm not sure in this situation how I should be pulling the state back. I've got two sets of arrays, one of 'things1' and one of 'things2'.
public struct DemoState: Equatable {
var things1: IdentifiedArrayOf<ThingState> = [ ThingState(data: "Label1"), ThingState(data: "Label2") ]
var things2: IdentifiedArrayOf<ThingState> = [ ThingState(data: "Data1"), ThingState(data: "Data2") ]
}
In my view, I want to iterate over the first array so that I can present NavigationLinks to a child view that shows one of thing1's and all of things2 (Thing12View):
ForEach(viewStore.things1, id: \.id) { thing in
NavigationLink(
destination:
Thing12View(store: self.store.scope(
state: {
Thing12ViewState(
thing: thing,
things2: $0.things2
)
},
action: { DemoAction.thing12(id: thing.id, action: $0) }
)),
label: {
Thing1View(store: self.store.scope(
state: { _ in thing },
action: DemoAction.thing
))
}
)
}
But I'm struggling with the correct set of reducers to pull my state back. As it stands, my state isn't updating properly. I think I need a way to pullback my Thing12ViewState
. Alternatively, perhaps I shouldn't be scoping a single array element in this way.
Another way to ask the question more simply: How do I send down and then pullback a single Identified item from my IdentifiedArray in the global state?
Sample project: https://www.dropbox.com/s/qjptguq3tqu7gom/foreach-nested_data.zip?dl=1