Glad I could help.

On Monday, 16 March 2015 08:02:40 UTC, Torsten Uhlmann wrote:
>
> Hi Colin,
>
> the thing I was missing is the entry point into the system, or a way to 
> get hold of my current component. After re-watching the talk and looking at 
> the slides (
> http://stuartsierra.com/download/2014-06-27-components-euroclojure.pdf) I 
> found him mentioning these on slides #94 to #105. So the ways he describes 
> to be able to pass a dependency as an argument to an API function of that 
> dependency are:
>
> - putting the system into a var or atom
> - adding a middleware to add the system or part of it to the request
> - create the routes in scope of the start function so you're able to pass 
> the component and dependencies around.
>
> These are the examples he mentioned, I'm sure there are other ways. But it 
> helped me to break out of that brain lock state of mine.
>
> Thanks for your extended help,
> Torsten.
>
>
> Am Sonntag, 15. März 2015 19:15:04 UTC+1 schrieb Colin Yates:
>>
>> If you haven't already then you might want to watch: 
>> https://www.youtube.com/watch?v=13cmHf_kt-Q 
>>
>> If it helps: 
>>
>> (defn a-real-worker [db] 
>>   ...) 
>>
>> (defrecord ARealWorkerComponent [db registry] 
>>   components/Lifecycle 
>>   (start [this] 
>>     (registry-api/register registry (partial a-real-worker-fn db)) 
>>     this) 
>>   (stop [this] 
>>     ....))) 
>> (defn a-real-worker-component [] 
>>   (map->ARealWorkerComponent {})) 
>>
>> ;; in the layer above these components 
>> (def system (components/systemmap 
>>   :db (infrastructure/new-db) 
>>   :a-real-worker (components/using 
>>     (a-real-worker-api/a-real-worker-component) 
>>     [:db])) ;; THIS IS WHERE IT GETS WIRED UP 
>>
>> So the real work is done in a-real-worker but it needs collaborators. 
>> It does that with ARealWorkerComponent (which probably also registers 
>> (a-real-worker...) with a registry of some sort. 
>>
>> When you call start the library will parse the 'using' meta-data to 
>> provide the dependencies the component needs. 
>>
>> Your question of how to actually *call* a-real-worker depends on your 
>> dispatching. Check out https://github.com/danielsz/system for some 
>> examples of using ring handlers for example. 
>>
>> HTH 
>>
>>
>> On 15 March 2015 at 17:30, Torsten Uhlmann <torsten...@gmail.com> wrote: 
>> > Colin, 
>> > 
>> > thanks for the thoughtful explanation! 
>> > 
>> > I still have a problem understanding the flow. Say I want to call a 
>> > component function (like "get-user") from another component that 
>> depends on 
>> > the database component. 
>> > 
>> > I still don't understand how a component function accesses it's 
>> > dependencies? There is the Lifecycle record that gets passed the 
>> > dependencies, constructs the component and returns a new map in the 
>> start or 
>> > stop function. But any function of that component is not defined inside 
>> the 
>> > scope of defrecord (correct ?) and the component map. So how would that 
>> > function access its own dependencies. 
>> > 
>> > I have the feeling that this problem comes from some very basic 
>> > misunderstanding on my end. Something very basic I'm missing. 
>> > 
>> > Thanks, 
>> > Torsten. 
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> > Groups "Clojure" group. 
>> > To post to this group, send email to clo...@googlegroups.com 
>> > Note that posts from new members are moderated - please be patient with 
>> your 
>> > first post. 
>> > To unsubscribe from this group, send email to 
>> > clojure+u...@googlegroups.com 
>> > For more options, visit this group at 
>> > http://groups.google.com/group/clojure?hl=en 
>> > --- 
>> > You received this message because you are subscribed to the Google 
>> Groups 
>> > "Clojure" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an 
>> > email to clojure+u...@googlegroups.com. 
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to