@James do you only have one component that has all of your routes? or do 
you have each component supply its own routes? If you imagine a component 
providing its own routes, I'd love to see a duct example with two routes 
set up.

I believe that would be multiple endpoint components.

Looking 
at 
https://github.com/weavejester/duct/blob/master/duct/src/duct/component/endpoint.clj#L7
 
I'm guessing that duct only expects one endpoint-component - is that 
correct?

-d



On Monday, June 8, 2015 at 8:36:36 PM UTC-5, James Reeves wrote:
>
> My recommendation is to use a closure. So I'd write your example as:
>
> (defn username-endpoint [{:keys [db]}]
>   (routes
>    (GET "/:username" [username]
>      (let [user (users/get-user db username)]
>        (str "<h1>Hello " (:name user) "</h1>")))))
>
> So you pass your configuration map into the endpoint function, which 
> returns a handler.
>
> You can then wrap this in a component:
>
> (defrecord EndpointComponent [build-routes]
>   component/Lifecycle
>   (start [component]
>     (if (:routes component)
>       component
>       (assoc component :routes (build-routes component))))
>   (stop [component]
>     (dissoc component :routes)))
>
> Incidentally, the above code is taken directly from Duct 
> <https://github.com/weavejester/duct>, a template and small supporting 
> library I've written for building component-based web apps.
>
> I've also written a blog article 
> <https://www.booleanknot.com/blog/2015/05/22/structuring-clojure-web-apps.html>
>  around 
> general best practice for this type of style.
>
> - James
>
>
> On 8 June 2015 at 22:51, Dru Sellers <d...@drusellers.com <javascript:>> 
> wrote:
>
>> So, I guess I am a bit lost, how does someone actually use component? I 
>> have an application all set up with it and it seems to be working as I 
>> would expect but Stuart seems to be steering me in a different direction. 
>>
>> https://github.com/stuartsierra/component/pull/35
>>
>> https://github.com/stuartsierra/component/issues/34
>>
>> So I'll try and paint a full picture.
>> https://gist.github.com/drusellers/8109dce4b9fb19c14ebb
>>
>> I know compojure and component / reloaded may not play well, but I'm 
>> trying to figure out how to best use the system var. Am I close, I'd love 
>> to give back a decent PR to the README.md of the component repo to help 
>> others as they come along.
>>
>> -d
>>
>> -- 
>> 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 
>> <javascript:>
>> 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 <javascript:>
>> 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 <javascript:>.
>> 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