This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-08
Channels
- # bangalore-clj (4)
- # beginners (160)
- # calva (132)
- # cider (18)
- # clara (1)
- # cljsrn (2)
- # clojure (129)
- # clojure-boston (1)
- # clojure-europe (5)
- # clojure-italy (5)
- # clojure-losangeles (1)
- # clojure-nl (33)
- # clojure-uk (49)
- # clojurescript (88)
- # cursive (20)
- # datomic (5)
- # duct (3)
- # fulcro (33)
- # graphql (7)
- # jobs (3)
- # kaocha (3)
- # nrepl (41)
- # off-topic (58)
- # pathom (18)
- # re-frame (1)
- # reagent (5)
- # shadow-cljs (148)
- # spacemacs (7)
- # tools-deps (7)
Does anyone here know why the values (from the server), that I am using as form fields are being removed from the data when I do add-form-config*
? Once I edit the field they populate, but the original values (and the key itself) are gone.
(defmutation edit-existing-booking
[{:keys [booking-id]}]
(action [{:keys [state]}]
(swap! state
(fn [s]
(-> s
(fs/add-form-config* BookingForm [:booking/by-id booking-id])
(fs/entity->pristine* [:booking/by-id booking-id])
(fs/mark-complete* [:booking/by-id booking-id])
(update-in [:booking/by-id booking-id] assoc :_id booking-id))))))
I ended up having to add the _id
back in, so my ident could find it - it was also missing
@njj not ringing any bells. add-form-config makes a form config based on the entity, it doesn’t touch it. Same with mark-complete and entity->pristine…all of them read it
the server not returning it is the only condition I can think of for it being removed (merge removes fields that were queried but not returned)
Yeah, the response is showing under :booking/by-id {"some-id-etc…": {}}
, which has tons of fields but for some reason the ones I’m defining as a form field are missing (or seem to have been removed)
As you can see in the mutation above, I had to end up adding the booking-id back because it was being removed too
The only logic in Fulcro itself that removes things it the mark/sweep merge. If you query if :id and the server does not return it, then Fulcro will remove it from state (since you asked for it and the server just indicated it didn’t exist). Any other removal (or unexpected removal like this) is most likely a bug in your logic. Check your server response.
@U0CKQ19AQ This is the entire mutation:
(defmethod m/mutation 'update-booking/fetch-booking [{:keys [state reconciler] :as env} _ {:keys [booking-id]}]
{:remote (m/remote-load env)
:action (fn []
(m/load-this! env [:booking] {:booking-id booking-id})
(swap! state
(fn [s]
(-> s
(fs/add-form-config* BookingForm [:booking/by-id booking-id])
(fs/entity->pristine* [:booking/by-id booking-id])
(fs/mark-complete* [:booking/by-id booking-id])))))})
load markers may be what is getting you…in the latest versions of Fulcro if you use the new client constructor loads default to not having load markers…that is almost certainly what is getting you
load-this!
is an abstraction made by the previous author, it wraps df/load-field-action, we use it to represent an api-read on the backend
(defn load-this!
[{:keys [state component ref] :as env} field params & vargs]
{:pre [(or (vector? params) (map? params) (fn? params)) (util/ident? ref)
(or (keyword? field) (vector? field))]}
(doseq [f (if (vector? field) field [field])]
(apply df/load-field-action
state component ref f
(apply concat
(merge {:marker false}
(dissoc vargs :params)
{:params
{f (cond
(fn? params) (params (get-in @state ref))
(vector? params) (-> (get-in @state ref)
(select-keys (filter keyword? params)))
(map? params) params)}}))))
env)
unfortunately I have no further ideas. Use inspect to see what query it is sending, and what response it is getting
ok I gave load-action
a shot, still seems to be removing the keys defined in form-fields
from my data so strange
(defmethod m/mutation 'update-booking/fetch-booking [{:keys [state reconciler] :as env} _ {:keys [booking-id]}]
{:remote (m/remote-load env)
:action (fn []
(m/load-this! env [:booking] {:booking-id booking-id})
(df/load-action env [:booking/by-id booking-id] BookingForm {:marker false
:params {:booking-id booking-id}
:post-mutation `edit-existing-booking
:post-mutation-params {:booking-id booking-id}}))})
why run both??? If the first is messing it up, aren’t you runnign the risk it still will?
@U0CKQ19AQ I got this working, thanks man!