You should have a "main" namespace where your app is started and this namespace 
should "require" all component namespaces you are going to use.

(ns project.main
  (:require [project.components.contacts]))

(start-the-app)

This way you ensure that all your namespaces are loaded in the proper order and 
unused namespaces are eliminated correctly. You should never assume that a 
namespace was loaded unless you required it somewhere you were going to use it.

Also as a side note: registering components in this global fashion will 
basically destroy any chance of any of the code ever benefiting from Closures 
dead code elimination.

A better pattern would be to

(ns project.components.contacts)

(def component (create-component ...))

(ns project.something
  (:require [project.components.contacts :as contacts]))

(om/build contacts/component {})

This way you don't need a registry at all and you always ensure a proper 
dependency graph and "some" of the unused code may be eliminated.

HTH,
/thomas

On Friday, March 13, 2015 at 3:54:08 AM UTC+1, Tyler Solomon wrote:
> Some code in my application is dependent upon some runtime specified code.  
> The
> problem is quite general, so please forgive my description by way of example. 
> 
> I'd like this root component to look up dependent components in map.
> 
> (q/defcomponent Root
>   "The root of the application"
>   [state]
>   (let [current-view (:current-view state)
>         Main (current-view registry/components)]
>     (d/div {}
>            (Main (current-view state)))))
> 
> ----
> 
> (ns project.component_registry)
> 
> (def components {})
> 
> (defn register-component 
>   [component resource-name]
>   (assoc components resource-name component))
> 
> 
> Included modules would register themselves:
> 
> 
> (ns project.components.contacts
>     (:require [project.component_registry :refer [register-component]]))
> 
> (declare Contacts) ;; some quiescent component defined here 
> 
> (register-component Contacts :contacts)
> 
> 
> I can see how I would specify dependencies with the newly supported
> Google Closure `:module` option, however I'm using Figwheel during 
> development,
> which requires `:optimizations :none`.
> 
> Can someone recommend how I might achieve this, or suggest a better approach? 
> Also, is this question more suited to StackOverflow?

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to