-
I've built a system with a hierarchy of of DaysFeature, DayFeature and Note Feature. At each level I'm using IdentifiedArrayOf and IdentifiedActionOf to embed the child in the parent
and this kind of forEach in the reducer:
If I have a naive system that just displays the full hierarchy:
And I repeat the system at the day/note level then everything works. I can add a day, add notes to it and at the top level save the data to a json file and open it back up next time. I then added navigation so it would show a list of days first, then choose the day to add and edit notes. When I add that code the parent no longer sees the state changes as they are now passed through the path.
I posted about this and the new shared state was mentioned as a possible way to make this work without having to use delegates to signal to the parent to save state. I tried looking at the syncup example in the shared state beta but it doesn't use this style of hierarchy for parents and children. The syncupslist has an array of syncups, a normal swift struct not a feature, a separate syncup detail feature is then used to edit the feature and shared state can pass around a syncup struct with no problem. I'm stuck with how I could use shared state with the structure I'm using. I can't work out how I'd use the $ notation for shared state in the foreach for the NavigationLinks. I'm just wondering if I'm looking at this in the wrong way as this way of embedding parents and children seems like a standard way to do things in TCA, as demonstarated in the ToDos example. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
It seems that If that were the case then that shared state could be passed along from the parent to the edit feature: NavigationLink(
state: DaysFeature.Path.State.editDay(
EditDayFeature.State(
someSharedState: dayStore.$someSharedState
)
)
) But also it's hard to give much concrete advice because there just isn't enough code and context to really understand what is going on in your situation. A minimal project that demonstrates the problem you are having would be the best way to get help. |
Beta Was this translation helpful? Give feedback.
-
I've uploaded a simple project with 2 targets. TCA Basic which uses parent/child relationships for Days/Day/Notes On both of these I've used I'm not trying to say there is any kind of bug with TCA, this is me not understanding how to use these tools correctly. |
Beta Was this translation helpful? Give feedback.
There's nothing to push back on 🙂. I am merely describing how value types work in Swift, and they just do not do what you are trying to get them to do. You have two separate copies of
DayFeature.State
in your app. One is held in thedays
identified array and the other in thepath
stack state. Those copies of state are fully separated, and the only way to keep them in sync is by the parent listening for actions in the child in order to replay those changes to the other copies.Not every case study is in the most pristine state. Bot…