How are people managing large component maps
is everyone just keeping it in one big file?
@drusellers: What exactly do you mean with "large component maps"?
@sveri: as I build out my application I’m seeing a pattern of components needing to be built - an endpoint / database calls / core logic that needs the database etc
if my application has 20 major features x 3-4 sub components per piece that would be 60 to 80 entries in the system map
then 60-80 using vectors
that just seems large to me
When I started using component I also noticed that the system map is getting larger and larger. However, I got accustomed to it and never noticed any drawbacks. So I don't really know if this is a problem or not, as long as it does not convolut my application logic, I am fine with that.
I mean, it's just a map with simple data, compared to other data that might flow / stay in your application it is nothing, usually
absolutely a fair point
i’m just new and have these random questions. :simple_smile:
i don’t want to make random assumptions.
Yea, like I said, starting out I had the same feeling, especially when I tried to understand the structure and see if I built them right, this is hard to do when the map is so large
how do you structure your map? i have like accounts
(core logic), accounts-endpoint
(compojure), accounts-db
(database access)
I structure them component wise, so one component for all compojure routes for instance, one for the server, one for the database
But, splitting them could also be an option, if it fits you better...
I’d say its a legacy of how I tend to think of code from C# where I could just type scan in all of these little components
i can see the value in one big endpoint with the way compojure does routing
so if you have one database component what does that look like for you?
(get-entityx db args)
(get-entityy db args)
and you just have 300 of those in the db.clj?
this is my database component, in the case of korma it just opens a db connection: https://github.com/sveri/closp/blob/master/resources/leiningen/new/closp/clj/components/db.clj
the thing with korma is, it just setups a default connection which can be used everywhere, so I dont even need to pass it around, so maybe this is a bad example
this is a config component: https://github.com/sveri/closp/blob/master/resources/leiningen/new/closp/clj/components/config.clj
and here at the bottom: https://github.com/sveri/closp/blob/master/resources/leiningen/new/closp/clj/routes/user.clj#L176
you can see them being passed to my routes
not sure if this answers your question, but this is how I always use them, so I have rather large components
it helps, just seeing examples
moving from a language that doesn’t like large code files to clojure which prefers them is a mental shift
My current system map looks like this: https://github.com/eventgonegood/app/blob/master/src/app/server/system.clj
and I just see my system map growing and growing
but my patterns are coming from C# and i’m trying to find my way into clojure patterns
:simple_smile:
and its weird seeing functions with all of these params still. 😜 (still thinking in method land)
It always helped me thinking in terms of something that can be start and stopped during development. So, when I dont need to restart single routes, I can keep them all in one component. But if I have extra routes for websockets for instance, they could be put into their own component
yeah, i have the reloaded process working and that is super nice
Also you dont need to have large source files, I am not sure if there is a best practice on that already in clojure. Keeping them small surely is a good thing
it helps me, but then i end up with this huge :require
in my system map
I need to find a way to better compose these things
I think you might try several approaches and see how they fit you
fair enough. :simple_smile:
Thank you very much for taking the time to chat through this with me. You have definitely helped me come to terms with a few things. :simple_smile:
and thank you for sharing your code
No problem, if you have more questions, just go ahead, talking about things often helps :simple_smile:
agreed
Remember that systems are just records, which are maps. If you have groups of components you can merge
them together.
I like to define using
dependencies in the component constructors, and only override them in the system map if necessary.