This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-31
Channels
- # announcements (2)
- # beginners (208)
- # boot (4)
- # calva (5)
- # cider (3)
- # clojars (3)
- # clojure (59)
- # clojure-dev (27)
- # clojure-india (2)
- # clojure-spec (46)
- # clojure-uk (3)
- # clojuredesign-podcast (4)
- # clojurescript (11)
- # cursive (10)
- # emacs (2)
- # figwheel-main (3)
- # off-topic (73)
- # onyx (1)
- # re-frame (8)
- # reagent (3)
- # rewrite-clj (12)
- # shadow-cljs (29)
- # spacemacs (1)
- # tools-deps (19)
I've been trying to get this xhrio co-effect to work. The core problem seems to be that db
is not present.
I can hard code the uri, and that works, but db
isn't there. So I have two problems, the uri is incomplete and worse,
it completely resets db
to nothing but show-twirly.
(reg-event-fx ;; note the trailing -fx
:http-inventory ;; usage: (dispatch [:http-inventory])
(fn [world [_ _]] ;; the first param will be "world"
(let [db (:db world)
server (str (:remote-server-path db) "api/products")]
{:db (assoc db :show-twirly true) ;; causes the twirly-waiting-dialog to show??
:http-xhrio {:method :get
:uri server
:timeout 8000 ;; optional see API docs
:response-format (ajax/json-response-format {:keywords? true}) ;; IMPORTANT!: You must provide this.
:on-success [::success-http-result]
:on-failure [::failure-http-result]}})))
I'm dispatching this from another event with dispatch[:http-inventory]. Maybe that is not good I don't know.
are you sure this event is clobbering the db? If the db is not there, you are returning (assoc nil :show-twirly true)
so you are correctly updating the db but someone upstream has already clobbered. This theory is bolstered by the fact that the uri is incomplete. This can be explained by a nil db coming in and therefore lacking the :remote-server-path
db. A super simple check is to log your db here and see if that's the case