-
Notifications
You must be signed in to change notification settings - Fork 53
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
Query for enhancement: CLJS support for import-vars #31
Comments
I'd encourage you to create a separate library for ClojureScript, it honestly seems easier. |
no problem |
@davesann if you've managed to do this for vars and functions in cljs, would you mind publishing it? Looks like there would be some interest more broadly. |
I haven't looked at this in a while. But it worked fine for my purposes. Very basic macros as I mentioned. I haven't pushed this to github yet. It was too small... but you are free to use as you wish if it meets your needs. (ns dsann.potemkin.cljs.namespaces)
(defmacro import-def
"import a single fn or var
(import-def a b) => (def b a/b)
"
[from-ns def-name]
(let [from-sym# (symbol (str from-ns) (str def-name))]
`(def ~def-name ~from-sym#)))
(defmacro import-vars
"import multiple defs from multiple namespaces
works for vars and fns. not macros.
(same syntax as potemkin.namespaces/import-vars)
(import-vars
[m.n.ns1 a b]
[x.y.ns2 d e f]) =>
(def a m.n.ns1/a)
(def b m.n.ns1/b)
...
(def d m.n.ns2/d)
... etc
"
[& imports]
(let [expanded-imports (for [[from-ns & defs] imports
d defs]
`(import-def ~from-ns ~d))]
`(do ~@expanded-imports))) |
@davesann Thanks for sharing. |
@davesann thanks for sharing :) |
I wanted to use an equivalent of import-vars in ClojureScript (actually, in cljx code for both). I tried Potemkin on the off chance that the pre-compile macro expansion of ClojureScript would work out ok. It didn't.
I have written a couple of very basic macros which match the signature of import vars and work for vars and functions in ClojureScript .
Would you like to include something like this into Potemkin? If yes, I thought namespace potemkin.cljs.namespaces (.clj). I can post the code for your review (it's short) or create a pull request.
The text was updated successfully, but these errors were encountered: