From 2b430185dcded7d4cdf274ff3c601dfd78df0cf9 Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Tue, 20 Feb 2018 15:05:51 -0800 Subject: [PATCH] [Fix #359] Workaround the transit-cljs map entry issue See also https://github.com/cognitect/transit-cljs/issues/42. --- src/cljs/snapshot/lumo/common.cljs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cljs/snapshot/lumo/common.cljs b/src/cljs/snapshot/lumo/common.cljs index 1cb88d06..855f0795 100644 --- a/src/cljs/snapshot/lumo/common.cljs +++ b/src/cljs/snapshot/lumo/common.cljs @@ -8,14 +8,25 @@ (def ^:private ^:const JSON_EXT ".json") +(def read-opts + {"cljs/MapEntry" (transit/read-handler (fn [[k v]] (MapEntry. k v nil)))}) + (defn transit-json->cljs [json] - (let [rdr (transit/reader :json)] + (let [rdr (transit/reader :json read-opts)] (transit/read rdr json))) +;; the read-opts and write-opts maps are necessary because of: +;; https://github.com/cognitect/transit-cljs/issues/33 +(def write-opts + {cljs.core/MapEntry + (transit/write-handler + (fn [_] "cljs/MapEntry") + (fn [entry] [(-key entry) (-val entry)]))}) + (defn cljs->transit-json [x] - (let [wtr (transit/writer :json)] + (let [wtr (transit/writer :json write-opts)] (transit/write wtr x))) (defn- load-core-analysis-cache