Skip to content

Commit

Permalink
Send query to pre-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkerlucio committed Dec 19, 2018
1 parent 5ca2aaf commit 6ac4de3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/main/fulcro/client/primitives.cljc
Expand Up @@ -956,7 +956,6 @@
(recur (next q) (assoc ret k x))))

;; normalize many

(and (vector? v) (not (util/ident? v)) (not (util/ident? (first v))))
(let [xs (into [] (map #(normalize* sel % refs union-entry transform)) v)]
(if-not (or (nil? class) (not #?(:clj (-> class meta :ident)
Expand Down Expand Up @@ -1570,20 +1569,23 @@
target
source))

(defn component-pre-merge [class state data]
(defn component-pre-merge [class query state data]
(if (has-pre-merge? class)
(let [entity (if #?(:clj (-> class meta :ident)
:cljs (implements? Ident class))
(get-in state (get-ident class data)))]
(pre-merge class {:state-map state :current-normalized entity :data-tree data}))
(pre-merge class {:state-map state
:current-normalized entity
:data-tree data
:query query}))
data))

(defn pre-merge-transform
"Transform function that modifies data using component pre-merge hook."
[state]
(fn pre-merge-transform-internal [query data]
(if-let [class (-> query meta :component)]
(component-pre-merge class state data)
(component-pre-merge class query state data)
data)))

(defn merge-handler
Expand Down
8 changes: 4 additions & 4 deletions src/test/fulcro/client/primitives_spec.cljc
Expand Up @@ -2093,10 +2093,10 @@

#?(:cljs
(assertions
(prim/merge-component {} MPersonPM (person :wilker "Wilker" [(phone-number 55 "98765-4321")]))
=> {:person/by-id {:wilker {:id :wilker
:name "Wilker"
:numbers [[:phone/by-id 55]]}}
(prim/merge-component {} MPersonPM (person :mary "Mary" [(phone-number 55 "98765-4321")]))
=> {:person/by-id {:mary {:id :mary
:name "Mary"
:numbers [[:phone/by-id 55]]}}
:phone/by-id {55 {:id 55
:number "98765-4321"
:ui/initial-flag :start}}}
Expand Down

0 comments on commit 6ac4de3

Please sign in to comment.