component

2016-10-25T00:03:38.000076Z

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

2016-10-25T00:03:50.000077Z

I wrote the following mount code:

2016-10-25T00:05:26.000079Z

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?

2016-10-25T00:07:16.000082Z

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

2016-10-25T00:08:02.000083Z

and what isn't working?

2016-10-25T00:08:46.000084Z

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

2016-10-25T00:09:26.000085Z

and the boilerplate seems a bit verbose

2016-10-25T00:09:29.000086Z

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

2016-10-25T00:11:00.000087Z

you are defining your own MainSystem

2016-10-25T00:11:07.000088Z

I wouldn't do that

2016-10-25T00:12:12.000089Z

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

2016-10-25T00:15:03.000092Z

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.

2016-10-25T00:21:25.000093Z

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

2016-10-25T00:23:30.000094Z

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

2016-10-25T00:24:28.000096Z

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

2016-10-25T00:32:03.000097Z

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