Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Transit clojure.lang.Var (de/s)erialization
diff --git a/src/main/clojure/cljs/analyzer.cljc b/src/main/clojure/cljs/analyzer.cljc
index 8bad1e0..c394196 100644
--- a/src/main/clojure/cljs/analyzer.cljc
+++ b/src/main/clojure/cljs/analyzer.cljc
@@ -61,7 +61,10 @@
{:handlers
{"cljs/js"
(reify com.cognitect.transit.ReadHandler
- (fromRep [_ v] (JSValue. v)))}})))
+ (fromRep [_ v] (JSValue. v)))
+ "cljs/var"
+ (reify com.cognitect.transit.ReadHandler
+ (fromRep [_ {:keys [ns name]}] (ns-resolve (symbol ns) (symbol name))))}})))
#?(:clj
(def transit-write-opts
@@ -71,6 +74,12 @@
(reify com.cognitect.transit.WriteHandler
(tag [_ _] "cljs/js")
(rep [_ js] (.val ^JSValue js))
+ (stringRep [_ _] nil))
+ clojure.lang.Var
+ (reify com.cognitect.transit.WriteHandler
+ (tag [_ _] "cljs/var")
+ (rep [_ js] (let [{:keys [ns name]} (meta js)]
+ {:name name :ns (.getName ^clojure.lang.Namespace ns)}))
(stringRep [_ _] nil))}})))
#?(:clj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment