This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-05
Channels
- # architecture (2)
- # aws (1)
- # bangalore-clj (4)
- # beginners (97)
- # boot (35)
- # cider (8)
- # cljsjs (3)
- # cljsrn (35)
- # clojure (190)
- # clojure-dusseldorf (4)
- # clojure-italy (7)
- # clojure-poland (1)
- # clojure-russia (17)
- # clojure-spec (74)
- # clojure-uk (30)
- # clojureremote (2)
- # clojurescript (298)
- # code-reviews (18)
- # component (18)
- # cursive (18)
- # datascript (3)
- # datavis (2)
- # datomic (24)
- # dirac (17)
- # emacs (3)
- # garden (7)
- # hoplon (51)
- # jobs (2)
- # jobs-rus (2)
- # leiningen (4)
- # luminus (11)
- # mount (24)
- # off-topic (1)
- # om (32)
- # onyx (25)
- # pedestal (1)
- # powderkeg (9)
- # protorepl (6)
- # re-frame (11)
- # reagent (15)
- # spacemacs (6)
- # sql (35)
- # uncomplicate (1)
- # unrepl (74)
- # untangled (130)
- # yada (6)
I have a component that shouldn't run in a dev environment Is there a preferred way for conditionally placing components into the system?
I use a hash-map each for the base system and the deps, and in some cases I merge components conditionally in the maps before starting, in others I dissoc conditionally
the former for optional prod-only things, the latter for special dev-only minimal systems
of course this means using apply instead of directly calling system-map
relevant snippet:
(let [system (virgin-system config-options)
deps (into {}
(filter (fn [[k v]]
(and (contains? system k)
(every? #(contains? system %) (vals v))))
kingfisher-deps))
system (mapcat (fn [[k v :as entry]]
(when (contains? deps k)
entry))
system)]
(-> (apply component/system-map system)
(component/system-using deps)))
this exactly what i needed, thank you!
ya I'd wondered about the system-map
thing, but your apply
solution is perfect
is a hash-map different from a map?
is it that the keys are hashed for faster lookup?
and maps aren't?
no, it's a map (I just say hash-map to differentiate from the function map is all)
oh nice. underneath, the normal map is still a hash map then?
clojure maps technically are either array-maps or hash-maps depending on size, but when they get big enough the array-maps auto-promote to hash-map
ah, thank you
oops, just too small
interesting, clojure really handles a lot of neat things behind the scenes...
thanks for pointing this out!
oh, the other thing is that the virgin-system
function takes a set of keys to dissoc as part of the config - the code I already shared prunes all deps that need those components