Fat State and Action for multi-level view hierarchies


Let's say that we have two views A and B. There is navigation from A to B and B is a fully separated view. B operates on Store<StateB, ActionB>. To be able to inject it from A we need to kind of have Store<StateA+B, ActionA+B> in A, which makes it a bit suboptimal (in A we have access to both state and actions designed for B).

I'm thinking theoretically, but I can imagine it can be pretty heavy in deep hierarchies. Is anybody concerned about such a problem? Maybe I'm not getting something right? Maybe you have some strategies for dealing with such a thing? Maybe that's not a problem at all?

Kind regards!

As far as I know it's not a problem. However, It can be only my ignorance.

Naturally It depends what does it mean fully separated views. If views doesn't needs to share any state or actions then you can just create sub-feature store and navigate into it. In most cases like this only Environment will be passed from parent to child (for example ApiClient.live instance) .

Most of the time you will need to pass state and actions from parent to child feature. Composing big stores with many small stores it's natural for TCA. In general it's not a problem if you observe changes only for what's really needed with ViewStore (scope store to just necessary state) in view the view.

However, in some extreme cases very big nested state can be problematic

You can manage access control to the child feature state properties as you need. You can also create ViewState intermediate state which will have some very local properties.
In case of actions you can't control access to particular enum cases. Therefore, parent have access to all action of the child. However to use this action you have to return from reducer explicit effect with child feature action so it's at least very "visible".

1 Like

Gotcha, I think I simply didn't get to the episode about ViewStores yet. I think this is the episode where it got introduced? I need to resubscribe after Christmas :slightly_smiling_face:

Thanks for the hint @Malauch :beers:

Yes, it is the right Pointfree episode about ViewStore concept. Next one is about adapting actions for ViewStore. By the way, I recommend analyzing isowords source code for some great examples of TCA in the wild.

1 Like
Terms of Service

Privacy Policy

Cookie Policy