Skip to content

Commit 9ab677a

Browse files
committed
Don't convert records to maps when reading
1 parent 8f31b2d commit 9ab677a

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/main/om/next/impl/parser.cljc

+5-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@
160160
([x path]
161161
(path-meta x path nil))
162162
([x path query]
163-
(let [x' (cond->> x
164-
(map? x) (into {} (map (fn [[k v]] [k (path-meta v (conj path k))])))
165-
(vector? x) (into [] (map-indexed #(path-meta %2 (conj path %1)))))]
163+
(let [x' (cond
164+
(record? x) x
165+
(map? x) (into {} (map (fn [[k v]] [k (path-meta v (conj path k))]) x))
166+
(vector? x) (into [] (map-indexed #(path-meta %2 (conj path %1)) x))
167+
:else x)]
166168
(cond-> x'
167169
#?(:clj (instance? clojure.lang.IObj x')
168170
:cljs (satisfies? IWithMeta x'))

src/test/om/next/tests.cljs

+16
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@
368368
{:value v}
369369
{:remote true}))
370370

371+
(defmethod read :location
372+
[{:keys [state]} k params]
373+
(if-let [v (get @state k)]
374+
{:value v}
375+
{:remote true}))
376+
371377
(defmethod read :woz/noz
372378
[{:keys [state]} k params]
373379
(if-let [v (get @state k)]
@@ -404,6 +410,16 @@
404410
(is (= (p {:state st} [:foo/bar] :remote) []))
405411
(is (= (p {:state st} [:foo/bar :baz/woz] :remote) [:baz/woz]))))
406412

413+
(defrecord Point [lat lon])
414+
415+
(deftest test-parse-defrecord
416+
(let [location (->Point 1 2)
417+
state (atom {:location location})
418+
result (p {:state state} [:location])]
419+
(is (= result {:location location}))
420+
(is (instance? Point (:location result)))
421+
(is (= (meta result) {:om-path []}))))
422+
407423
(deftest test-value-and-remote
408424
(let [st (atom {:woz/noz 1})]
409425
(is (= (p {:state st} [:woz/noz]) {:woz/noz 1}))

0 commit comments

Comments
 (0)