From c7d0a8596b124cb409a7abae71bc7b7fe2f6ebcc Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Wed, 5 Oct 2016 12:54:26 -0700 Subject: [PATCH] Part 2: extend 'cljify' implementation to round-trip records like TempId. --- src/node/datomish/cljify.cljs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/node/datomish/cljify.cljs b/src/node/datomish/cljify.cljs index 3ef64a3f..fe8691df 100644 --- a/src/node/datomish/cljify.cljs +++ b/src/node/datomish/cljify.cljs @@ -1,7 +1,27 @@ (ns datomish.cljify) (defn cljify - "In node, equivalent to `(js->clj o :keywordize-keys true). - See ." - [o] - (js->clj o :keywordize-keys true)) + "In node, equivalent to `(js->clj o :keywordize-keys true), + but successfully passes Clojure Records through. This allows JS API + callers to round-trip values they receive from ClojureScript APIs." + [x] + (if (record? x) + x + (cond + (satisfies? IEncodeClojure x) + (-js->clj x (apply array-map {:keywordize-keys true})) + + (seq? x) + (doall (map cljify x)) + + (coll? x) + (into (empty x) (map cljify x)) + + (array? x) + (vec (map cljify x)) + + (identical? (type x) js/Object) + (into {} (for [k (js-keys x)] + [(keyword k) (cljify (aget x k))])) + + :else x)))