Skip to content

Commit f63acfd

Browse files
committed
Don't convert records to maps when reading
1 parent 4173d01 commit f63acfd

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
@@ -157,9 +157,11 @@
157157
key)))))))
158158

159159
(defn path-meta [x path]
160-
(let [x' (cond->> x
161-
(map? x) (into {} (map (fn [[k v]] [k (path-meta v (conj path k))])))
162-
(vector? x) (into [] (map-indexed #(path-meta %2 (conj path %1)))))]
160+
(let [x' (cond
161+
(record? x) x
162+
(map? x) (into {} (map (fn [[k v]] [k (path-meta v (conj path k))])) x)
163+
(vector? x) (into [] (map-indexed #(path-meta %2 (conj path %1))) x)
164+
:else x)]
163165
(cond-> x'
164166
#?(:clj (instance? clojure.lang.IObj x')
165167
:cljs (satisfies? IWithMeta x'))

src/test/om/next/tests.cljs

+16
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@
236236
{:value v}
237237
{:remote true}))
238238

239+
(defmethod read :location
240+
[{:keys [state]} k params]
241+
(if-let [v (get @state k)]
242+
{:value v}
243+
{:remote true}))
244+
239245
(defmethod read :woz/noz
240246
[{:keys [state]} k params]
241247
(if-let [v (get @state k)]
@@ -272,6 +278,16 @@
272278
(is (= (p {:state st} [:foo/bar] :remote) []))
273279
(is (= (p {:state st} [:foo/bar :baz/woz] :remote) [:baz/woz]))))
274280

281+
(defrecord Point [lat lon])
282+
283+
(deftest test-parse-defrecord
284+
(let [location (->Point 1 2)
285+
state (atom {:location location})
286+
result (p {:state state} [:location])]
287+
(is (= result {:location location}))
288+
(is (instance? Point (:location result)))
289+
(is (= (meta result) {:om-path []}))))
290+
275291
(deftest test-value-and-remote
276292
(let [st (atom {:woz/noz 1})]
277293
(is (= (p {:state st} [:woz/noz]) {:woz/noz 1}))

0 commit comments

Comments
 (0)