Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClojureScript support for read-string #73

Closed
kwrooijen opened this issue Jan 24, 2020 · 4 comments · Fixed by #75
Closed

ClojureScript support for read-string #73

kwrooijen opened this issue Jan 24, 2020 · 4 comments · Fixed by #75

Comments

@kwrooijen
Copy link
Contributor

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's read-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.

@weavejester
Copy link
Owner

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?

@kwrooijen
Copy link
Contributor Author

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 😄

@kwrooijen
Copy link
Contributor Author

@weavejester Is this enough information for you? If you're ok with this change then I can start writing the pull request.

@weavejester
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants