Replies: 2 comments 5 replies
-
Hey @mariob. I don't think that it'll worth it in the case of a tabbed application. In such apps, there is only one tab visible, hence only one active branch at a given moment. The other stores for the inactive tabs are non-existing (even if their idle state can be stored in the root state). It can make sense to uncouple a few stores in complex apps that are presenting many features at the same time (e.g. Mac apps), but I think the gain will be not be significative for a tabbed app, provided your Without weighting yet on the pros and cons of what you're suggesting, do you have effective bottlenecks in your current situation? |
Beta Was this translation helpful? Give feedback.
-
You can a) Hold each store inside b) Initialize all four stores at the root of the app like the root store c) Hold the four stores each in a static variable. d) Hold the stores inside a dependency that maintains, syncs and returns them. I did a) for composability+for automatic deinit and a small bit d), but I would probably choose b) or c) for simplicity if I could and d) if it is many stores of the same type.. or maybe c) and d) are equivalent. Don't choose a) If you wanna reorder tabs on-the-fly while depending on .tasks for initializing and updating the stores. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I'm currently building an iOS application with 4 tabs and I'm considering using a multi-store architecture to manage the state of the app (pretty much a store per tab). My concern is that using a single store for the entire app could result in a lot of unnecessary "state updates" for actions that don't affect the other tabs. By isolating each tab to its own store, I hope to reduce the amount of traffic and improve the app's performance.
For example, I'm using the 'computed property' pattern for child-states, which creates a new instance each time an action enters the store and each Scope(...) is evaluated. I'm not doing anything in the child feature's inits and only property assignments in child feature's state init but still a lot of unnecessary computation is happening. It sounds that this should be negligible for 4-5 scoped child features, but maybe I'm wrong?
However, using multiple stores means I'll need to use stateful clients to share data between them, which is not a problem but I like the idea of having the user's data in the root state and just have stateless clients if possible. Currently, I have a significant portion of my app's data stored in the root reducer's state, which is shared among three of the child reducers (i.e. the tabs). If I switch to a multi-store architecture, I'll lose that ability.
A thing that I appreciate with having stateless clients is that the session's data is automatically cleaned at logout because the 'AppFeature.State' is replaced with 'SignInFeature.State' (enum routing).
Another downside with putting the shared state in dependencies are that I need to start to subscribe for data-change notifications via AsynStream or something similar to update the state, which requires running a long-living effect in each tab.
I'm wondering if anyone else has experience using TCA with a multi-store architecture in a similar setting? If so, how did it work for you? Did you encounter any issues or limitations? Did you reverted back to a single store?
Any feedback or advice would be greatly appreciated!
Thanks,
Mario
Beta Was this translation helpful? Give feedback.
All reactions