Last active
June 9, 2016 23:05
-
-
Save JacobNinja/dd488daced80960c7ed5c547f4a39854 to your computer and use it in GitHub Desktop.
Transit clojure.lang.Var (de/s)erialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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