Closed kwrooijen closed 4 years ago
It would add an extra dependency to Integrant, but also would only be one more. Could you explain a little more about your use-case? Your configuration is being served from a HTTP server?
I have an HTTP server that serves Content-Type: application/edn
. And multiple integrant based services that call this HTTP server. One of them being a ClojureScript application. The CLJS application makes an HTTP call, the EDN arrives as text. I then use (my copied) ig/read-string
function on the payload.
Another (future) use-case is that I want to build an electron application, and add edn
files in the build. Since the electron will build a package with the edn files included, this becomes possible.
Also, not entirely relevant to this issue but you might be wondering:
"If you add a new key to the remote server, and don't add the init-key
to the CLJS application, it will break"
Basically the CLJS client decides what to do with this structure, if new keys get added, it shouldn't affect the system. So any undefined keys inherit from a const
init-key.
(defmethod ig/init-key :my-lib/const [_ opts]
opts)
(defn undefined-keys->const
[config]
(doseq [k (keys config) :let [k (parse-key k)]]
(when-not (contains? (methods ig/init-key) k)
(derive k :my-lib/const))))
....
(undefined-keys->const (ig/read-string config))
Adding an options map to ig/read-string
, for example (ig/read-string {:derive-missing-keys :my-lib/const} config)
could come in handy (in my case, at least). But that's for another issue 😄
@weavejester Is this enough information for you? If you're ok with this change then I can start writing the pull request.
Yes, that's fine. I think it's worth making the tools.reader dependency a provided one, since ClojureScript includes it as a default dependency, so it should be the case that if we're working with ClojureScript, then we already have it in our dependency graph.
Problem
Currently I have a setup with an HTTP server that returns EDN. I need to be able to read this from my ClojureScript application. However
ig/read-string
is currently only available for Clojure. Possibly for the lack of a built-in EDN library?Solution
We could add tools.reader as a dependency to integrant. That way we can import
cljs.tools.reader.edn
specifically for ClojureScript. This would really help me since I'm now copy pasting integrant'sread-string
function in my ClojureScript application.What do you think of this idea? Do you possibly have a reason to not support ClojureScript? If you agree to this change then I'd be willing to create a pull request, to save you the hassle.