day8 / re-frame-http-fx

A re-frame "effects handler" for performing Ajax tasks (via cljs-ajax)
MIT License
259 stars 27 forks source link

Pass original event id to :on-success and :on-failure #51

Closed sirmspencer closed 5 months ago

sirmspencer commented 1 year ago

For logging and other events, its good to track the to original caller of the http request. Since internally, on- is re-dispacted the event name in the fx [{:keys [db]} [event-name response]] is that of the event specified in on-. For specific events and success handlers, I can obviously pass in the event name of the caller. However this breaks down for generic handlers, and the default fallback events.

Passing works if possible

(rf/reg-event-fx
  :on-failure
  (fn [{:keys [db]} [event-name calling-event response]]
    ...))

For example, our default on-failure warns that the error should be handled. It's hard to track down where the warning is thrown from because I can't pull the original calling event name.

(rf/reg-event-db
  :http-no-on-failure
  (fn [db]
    (js/console.warn "Uncaught xhrio failure.  Consider catching and setting loading state with :basic-xhrio-failure")))
kimo-k commented 5 months ago

Hey, I've thought about it for a bit, but I don't see a way to do this without breakage. Feel free to submit a PR, though. There might be a nice solution to be found.