Fork me on GitHub

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


what's the source of the event you are dispatching this from?


I have a button that dispatches to an event that decides to update in-app with generated test data or to do the http request. It dispatches in an if. And oh, I think I see. That event never returns db so it gets clobbered there. So that should be an fx also.


Im on a walk, or I'd try it. But I'm pretty sure that's it.


That was it. Thank you so much. Sometimes its good just to talk through it.