This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-29
Channels
- # announcements (6)
- # babashka-sci-dev (15)
- # beginners (46)
- # calva (1)
- # clj-kondo (1)
- # clojure-australia (2)
- # clojure-europe (10)
- # clojure-uk (4)
- # clojured (3)
- # clojurescript (16)
- # fulcro (6)
- # helix (1)
- # hyperfiddle (8)
- # instaparse (28)
- # joyride (33)
- # malli (17)
- # off-topic (13)
- # pedestal (3)
- # portal (5)
- # react (1)
- # sci (1)
- # sql (6)
- # vim (1)
I’ve got an ^:export-ed function. I can call it directly by (js/my.function_name)
, but how invoke it if I only have its fully qualified name as a string (“my.function_name”)?
Hey, @U05224H0W thanks. I’m not sure it’s going to work on advanced optimizations. Had to mention that in the original question,
You’re right, my auto-export macro doesn’t work properly. Released code has js/my.function_name
but js/goog.getObjectByName
returns null. When I manually add ^:export to the function body it works both ways.
(println
js/my.function_name
(js/goog.getObjectByName "my.function_name"))
it prints only js/… lineIt scans edn file for symbols.
(defmacro scan-exports!
[path]
(let [graph# (edn/read-string (slurp path))
vars (gather-syms graph#)]
(doseq [v vars]
(println "adding v" v)
(alter-meta! v assoc :export true))
`'~graph#))
And why it adds js/my.function_name
? If I comment out macro usage, js won’t have my function
(defmacro scan-exports!
[path]
(let [graph (edn/read-string (slurp path))
vars (gather-syms graph)]
`(do ~@(for [v vars]
`(js/goog.exportSymbol ~(comp/munge v) v))
~graph)))
this requires however that the namespace using this MUST have a proper ns require for all the namespaces you are using in the edn file
Thanks a lot, @U05224H0W. Your shadow-cljs work is immeasurable.