Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't convert records to maps when reading #551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/om/next/impl/parser.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
16 changes: 16 additions & 0 deletions src/test/om/next/tests.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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}))
Expand Down