Fork me on GitHub
#component
<
2016-10-25
>
josh.freckleton00:10:38

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...

josh.freckleton00:10:50

I wrote the following mount code:

josh.freckleton00:10:26

And attempted the following component code, but, it seems way more complex, and I think I'm not associng the keys I thought I was, how can I port that mount code appropriately?

josh.freckleton00:10:16

(basically, i just want to fetch * from a postgres db)

hiredman00:10:02

and what isn't working?

josh.freckleton00:10:46

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?)

josh.freckleton00:10:26

and the boilerplate seems a bit verbose

hiredman00:10:29

right, having something to wire a system together when you have only one part of a system is overkill

hiredman00:10:00

you are defining your own MainSystem

hiredman00:10:07

I wouldn't do that

hiredman00:10:12

if you look at the examples, they call system-map, which works just fine, no need to reinvent it

hiredman00:10:03

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.

hiredman00:10:25

You also may want to call the generated constructor functions for records directly instead of wrapping them

hiredman00:10:30

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

hiredman00:10:28

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

josh.freckleton00:10:03

@hiredman thanks for the tips, i'll be excited to tweak stuff tomorrow to incorporate this!