Keep root components from being huge #438
Replies: 1 comment 1 reply
-
I think what you are asking are very important questions that do not have a single answer and may also be very opinionated. I think it strongly depends on how you normally organize your code, what your previous experience taught you and on what project and part of the project you are currently working. The library and frameworks in general with their sample projects are a great starting point and provide you a lot of best practices, but they are not always fitting well into your project's needs and provide often only basic use-cases. If I had to give you a quick answer it would be "Prefer to break things down. Components should be light-weighted and having a lot of components is to be expected in production-ready apps." But someone might give you a better or completely different answer. That's why I want to share a few tips that helped me organize larger (normally production-ready) applications (you may already know these, but see them as a reminder then). Create and keep up-to-date an information architecture and navigation systemNo matter at what stage your project is, having and updating the information architecture and the navigation system (typically as a graph) will help you to quicker identify possible abstractions and relations between components. It may also allow you to recognize various data flows that may not be obvious at first. Remember the SOLID principlesThe SOLID principles contain valuable information on how you should design your components, how to abstract and couple things together. They play an important role in object-oriented programming and also in software architecture. I strongly recommend to document your components. This helped me focus more on the single-responsibility principle, because once I started writing down what a component's role was, I realized that I was giving it too many responsibilities. Only then I realized that I had to split it even further and create various components with different responsibilities. And thanks to the AI assistant I now write much more doc comments. Try things out and don't be afraid of changing things over timeProbably the most important thing for me is trying things out. Go with a solution and don't loose time. And if it won't work out, make the necessary changes. It's hard to find the perfect solution on the first try and because the requirements of a project are constantly changing, you will have to reevaluate and rewrite parts of your project. Thanks to the great practices and design patterns that are followed and used in this and other related libraries, it is quite easy to make changes and don't introduce often crucial and large-scale changes. Starting with fewer components and later splitting them up to multiple components, abstracting them with wrappers or interfaces and rewriting them is part of the software development process and easy to master. Just know your code's limitations, try alternatives and form your own and unique experience based on your needs. Additional notesSome important features of Decompose that are worth mentioning for all your planning and designing are:
|
Beta Was this translation helpful? Give feedback.
-
Hi. Thanks for amazing lib. I wonder what options do we have to slow down component growth if we talk about some root components.
Let's say we have an app like Twitter, so we have AuthorizedRoot with all these bottom tabs and a lot of other screens open on the same navigation level. For example Single Tweet screen, Account screen, Compose New Tweet screen, Photo Attachment screen, Video Attachment screen and much much more.
So basically our
DefaultAuthorizedRootComponent
may look kind of like this:I believe I am losing control on how much code do I have here with every new feature. Like what if I add Settings, Direct Messages Chat screen, anything else which I want to open on top of Main bottom nav screen, not inside its tab. If I continue I'll get long when statement, a lot of child create methods, long Child sealed class here. How do you think we should decompose (no pun intended) such big components to smaller ones? All of these features are kind of on the same business level, it feels unnatural to separate them.
Beta Was this translation helpful? Give feedback.
All reactions