This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-14
Channels
- # beginners (4)
- # boot (78)
- # braveandtrue (3)
- # cider (9)
- # clara (6)
- # cljs-dev (4)
- # clojure (57)
- # clojure-brasil (1)
- # clojure-russia (99)
- # clojure-spec (20)
- # clojure-uk (40)
- # clojurescript (162)
- # component (17)
- # cursive (4)
- # datomic (21)
- # docker (2)
- # emacs (5)
- # figwheel (2)
- # hoplon (363)
- # jobs (1)
- # leiningen (1)
- # om (4)
- # om-next (5)
- # onyx (10)
- # proton (1)
- # re-frame (13)
- # reagent (13)
- # ring (3)
- # rum (1)
- # slack-help (1)
- # test-check (3)
- # untangled (7)
- # vim (24)
If I want to expose an environment variable to reagent from the server (using the lein reagent-template), what is the usual way?
You can use a macro
The macro is evaluated at compile-time in Clojure code, which has access to environment variables
And if you aren't using clojure for your backend, there's always the good ol' standby of prepending "SERVER_DATA = {...}" To the js file you are serving
Which, while problematic for reasons people here will gladly point out, is relatively easy to set up
(if js/SERVER_DATA) (... Add data to app state ...) (def js/SERVER_DATA (clj->js {})))
I actually like @emccue's approach better than (ab)using a macro for selecting an environment