I'm developing RIA with clojure and clojurescript. Backend uses hiccup to generate a resulting html, like
(html5
[:head
(include-js "/js/my-cljs-generated.js")]
[:body ... ])
How can I pass edn(hashmap, vector, etc.) to clojurescript within the resulting html, i.e. without doing ajax call?
I would like to make hiccup do something like this:
(include-edn
"var_name" {:foo :bar}) ; or any other clojure data
and to be able to access the passed edn from cljs somehow(e.g. by name).
Currently my implementation is a bit hacky and stores edn in a global js var
(hiccup/javascript-tag (str "var edn = \""
(pr-str my-clojure-data) "\";"))
and on cljs side does smth like
(jayq/document-ready
(fn []
(if-let [edn (.-edn js/window)]
(do-something-with (cljs.reader/read-string edn))
)
...
)
Maybe there is more idiomatic way of achieving this?