weavejester / integrant

Micro-framework for data-driven architecture
MIT License
1.22k stars 63 forks source link

ClojureScript read config.edn parity via macros #66

Closed clyfe closed 3 years ago

clyfe commented 4 years ago

I believe we can introduce cljs feature parity with some of the fns that are currently clj-only (basically read-string & load-namespaces) by means of macros, at least to some extent. Example:

foo (a clojurescript project)
├── resources
│   └── foo
│       └── config.edn
└── src
    └── foo
        ├── core.clj
        └── core.cljs
;;; resources/foo/config.edn
{:foo/bar "42"
 :foo/baz #ig/ref :foo/bar}
;;; src/foo/core.clj
(defmacro read-config [path]
  (-> path io/resource slurp ig/read-string))
;;; src/foo/core.cljs
(def config (read-config "foo/config.edn"))
;; {:foo/bar "42"
;;  :foo/baz #integrant.core.Ref{:key :foo/bar}}

If this seems desirable I can make a more concrete proposal and PR.

weavejester commented 4 years ago

Thanks for the interesting suggestion. I'm a little leery about having read-config be a macro, but less wary about load-namespaces. I'll give it some thought.

clyfe commented 3 years ago

How about we have them as macros only in cljs? Options imho are: a) Not have them in cljs. b) Have them as macros in cljs.

weavejester commented 3 years ago

read-config could be a function if the backend was nodejs, I believe. It's sometimes better to omit behaviour that's inconsistent and allow for user implementations.