Fork me on GitHub

I have a use case where I want to ^:export some variables for JS consumption - the build in shadow is :npm-module. To clean things up I wanted to do export a cljs var within a macro, but I'm struggling to find a way to do so - attaching the metadata to the resulting cljs var doesn't get shadow to include the var in the module.exports. I can goog.exportSymbol manually in the macro code, but I do I also need the JS var in the module.exports object. Is this a known limitation or is there a way to get this working?


@danvingo what did you do in the macro? shadow collects the data from the analyzer meta data so if you did it correct it should just work


the background context is I'm trying to create some react storybook stories - which in the newer versions are just functions that are exported. Here's the code:

(defmacro make-story2 [nm body]
  `(defn ^:export ~nm []
     (reagent.core/as-element ~body)))
I've also tried:
(defmacro make-story2 [nm body]
     (defn ~nm []
       (reagent.core/as-element ~body))
     (alter-meta! (var ~nm) assoc :export true)))


ahhhh I found the magic incantation 🙂

(defmacro make-story2 [nm body]
  `(defn ~nm
     {:export true} []
     (reagent.core/as-element ~body)))


hmm, so this works for defn, but not for def I guess I can refactor to use defn


^:export ~nm [] isn't valud


~(vary-meta nm assoc :export true) would do it


(defmacro make-story2 [nm body]
  `(defn ~(vary-meta nm assoc :export true) []
     (reagent.core/as-element ~body)))


I figured the reader macro wouldn't work - ahh very cool!


thanks for the help