Fork me on GitHub
#reagent
<
2017-01-14
>
davin19:01:43

Can someone point me in the right direction about client config?

davin19:01:28

If I want to expose an environment variable to reagent from the server (using the lein reagent-template), what is the usual way?

davin19:01:21

I couldn’t reference environ (for obvious reasons)

pesterhazy19:01:19

You can use a macro

pesterhazy19:01:19

The macro is evaluated at compile-time in Clojure code, which has access to environment variables

emccue21:01:11

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

emccue21:01:28

Which, while problematic for reasons people here will gladly point out, is relatively easy to set up

emccue21:01:36

You could also send it as a separate file, which is even lazier

emccue21:01:44

Then put something like

emccue21:01:06

(if js/SERVER_DATA) (... Add data to app state ...) (def js/SERVER_DATA (clj->js {})))

emccue21:01:33

Just be sure to extern SERVER_DATA and that hack should hold together

pesterhazy21:01:41

I actually like @emccue's approach better than (ab)using a macro for selecting an environment

emccue21:01:46

I don't have a computer in front of me to test this, but maybe (def ^:export js/SERVER_DATA js/SERVER_DATA) could side step having to make an externs file