From 9ab677af2f59b3d32fe5fa4e24470ce9c4ca1aab Mon Sep 17 00:00:00 2001 From: Roman Scherer Date: Wed, 23 Dec 2015 22:35:22 +0100 Subject: [PATCH] Don't convert records to maps when reading --- src/main/om/next/impl/parser.cljc | 8 +++++--- src/test/om/next/tests.cljs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/om/next/impl/parser.cljc b/src/main/om/next/impl/parser.cljc index 5e0fcf59..7ba21234 100644 --- a/src/main/om/next/impl/parser.cljc +++ b/src/main/om/next/impl/parser.cljc @@ -160,9 +160,11 @@ ([x path] (path-meta x path nil)) ([x path query] - (let [x' (cond->> x - (map? x) (into {} (map (fn [[k v]] [k (path-meta v (conj path k))]))) - (vector? x) (into [] (map-indexed #(path-meta %2 (conj path %1)))))] + (let [x' (cond + (record? x) x + (map? x) (into {} (map (fn [[k v]] [k (path-meta v (conj path k))]) x)) + (vector? x) (into [] (map-indexed #(path-meta %2 (conj path %1)) x)) + :else x)] (cond-> x' #?(:clj (instance? clojure.lang.IObj x') :cljs (satisfies? IWithMeta x')) diff --git a/src/test/om/next/tests.cljs b/src/test/om/next/tests.cljs index 4d551114..8c5a53ae 100644 --- a/src/test/om/next/tests.cljs +++ b/src/test/om/next/tests.cljs @@ -368,6 +368,12 @@ {:value v} {:remote true})) +(defmethod read :location + [{:keys [state]} k params] + (if-let [v (get @state k)] + {:value v} + {:remote true})) + (defmethod read :woz/noz [{:keys [state]} k params] (if-let [v (get @state k)] @@ -404,6 +410,16 @@ (is (= (p {:state st} [:foo/bar] :remote) [])) (is (= (p {:state st} [:foo/bar :baz/woz] :remote) [:baz/woz])))) +(defrecord Point [lat lon]) + +(deftest test-parse-defrecord + (let [location (->Point 1 2) + state (atom {:location location}) + result (p {:state state} [:location])] + (is (= result {:location location})) + (is (instance? Point (:location result))) + (is (= (meta result) {:om-path []})))) + (deftest test-value-and-remote (let [st (atom {:woz/noz 1})] (is (= (p {:state st} [:woz/noz]) {:woz/noz 1}))