-
In the example of a Standups, how can we refresh the child screen from the parent? struct AppFeature: ReducerProtocol {
...
var body: some ReducerProtocolOf<Self> {
Scope(state: \.standupsList, action: /Action.standupsList) {
StandupsList()
}
Reduce<State, Action> { state, action in
switch action {
case let .didUpdate(standup):
state.standupsList.standups[id: standup.id] = standup
// Updating the standup list here won't refresh the state and UI of the detail screen since the detail screen's state is a copy of the parent
// Can we synchronize the state by traversing the stack state?
state.path.ids.forEach { id in
if state.path[id: id, case: /Path.State.detail]?.standup.id == standup.id {
state.path[id: id, case: /Path.State.detail]?.standup = standup
}
}
return .none
}
...
}
...
}
|
Beta Was this translation helpful? Give feedback.
Answered by
mbrandonw
Jul 18, 2023
Replies: 1 comment 1 reply
-
Hi @xspyhack, yeah that is technically one way you can do it. But also if the root list of standups is updating frequently, and those changes need to be played back to any screens in the stack, then I think a completely different approach should be taken. It would be better to model the |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
xspyhack
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @xspyhack, yeah that is technically one way you can do it. But also if the root list of standups is updating frequently, and those changes need to be played back to any screens in the stack, then I think a completely different approach should be taken. It would be better to model the
standups
collection as a dependency so that it could be observed by any feature more easily. That takes more work to do, but it would set you up better for the future.