Part 2: extend 'cljify' implementation to round-trip records like TempId.

This commit is contained in:
Richard Newman 2016-10-05 12:54:26 -07:00
parent 0b6ac81ed5
commit c7d0a8596b

View file

@ -1,7 +1,27 @@
(ns datomish.cljify) (ns datomish.cljify)
(defn cljify (defn cljify
"In node, equivalent to `(js->clj o :keywordize-keys true). "In node, equivalent to `(js->clj o :keywordize-keys true),
See <http://dev.clojure.org/jira/browse/CLJS-439?focusedCommentId=43909>." but successfully passes Clojure Records through. This allows JS API
[o] callers to round-trip values they receive from ClojureScript APIs."
(js->clj o :keywordize-keys true)) [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)))