We'd been talking a bit on the main #clojure channel about component
vs mount
, and while I quickly grasped mount
, I'm struggling to translate to component
...
I wrote the following mount
code:
And attempted the following component
code, but, it seems way more complex, and I think I'm not assoc
ing the keys I thought I was, how can I port that mount
code appropriately?
(basically, i just want to fetch *
from a postgres db)
and what isn't working?
well, it works, but it seems like i'm hitting a nail with a nuke (I'm guessing it becomes more useful at a bigger scale?)
and the boilerplate seems a bit verbose
right, having something to wire a system together when you have only one part of a system is overkill
you are defining your own MainSystem
I wouldn't do that
if you look at the examples, they call system-map, which works just fine, no need to reinvent it
I have noticed other people like to use component/using
like you did for declaring dependencies, I prefer using component/system-using
, so I have one map that is like an environment, mapping names of components to instances of that component, and another map that is the dependency tree of the components in the environment.
You also may want to call the generated constructor functions for records directly instead of wrapping them
https://github.com/hiredman/songs-of-future-past/blob/master/src/com/manigfeald/sofp.clj#L91-L128 isn't a great project, but it is the only public code I have using component, and you at least get an idea for what things could look like with more components
component is also super flexible, at the last place I worked, for one project we swapped out the LifeCycle protocol on records, for lifecycle multimethods on plain maps
@hiredman thanks for the tips, i'll be excited to tweak stuff tomorrow to incorporate this!