This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-05
Channels
- # adventofcode (89)
- # announcements (9)
- # babashka (11)
- # beginners (8)
- # biff (5)
- # calva (4)
- # cherry (121)
- # clara (15)
- # clerk (16)
- # clj-kondo (20)
- # clj-otel (2)
- # cljdoc (20)
- # clojure (84)
- # clojure-austin (1)
- # clojure-bay-area (3)
- # clojure-berlin (1)
- # clojure-czech (2)
- # clojure-europe (59)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-poland (1)
- # clojure-uk (15)
- # cursive (16)
- # datomic (46)
- # events (3)
- # fulcro (85)
- # graalvm (20)
- # hyperfiddle (11)
- # improve-getting-started (1)
- # lsp (7)
- # off-topic (48)
- # overtone (8)
- # podcasts-discuss (4)
- # re-frame (31)
- # releases (1)
- # ring (12)
- # sci (13)
- # shadow-cljs (8)
- # specter (3)
- # squint (26)
- # xtdb (5)
- # yamlscript (6)
I've run into a bug where POST requests to a server are sometimes failing when I use my app on my phone. In trying to debug this, I've found that I can't get re-frame-http-fx
to give me both the server's response and extra data I passed in to :on-success
. The docs say:
> These event vectors will be dispatched (`result` is conj
-ed to the end) making all encoded values AND the result
available to the handlers.
Which makes me think it's possible, but I'm missing something.
You can use on-success
and on-failure
and pass data. I assume you want data to be available in your on-failure
method (as your request fails)? Works for POST as well.
(reg-event-fx
:some-useful-get
(fn [db [_ data]]
{:http-xhrio {:method :get
:uri your-url
:timeout 5000
:response-format (ajax/json-response-format {:keywords? true})
:on-success [:your-success-method data]
:on-failure [:your-failure-method data]}})))
(reg-event-db
:your-success-method
(fn [db [_ data result]]
....)
(reg-event-db
:your-failure-method
(fn [db [_ data result]]
....)
@U2FRKM4TW The problem is my on-success is being fired, which I can see because it takes the item being submitted out of the "shopping basket". And the printlns in the function also get called.
So I think it's a problem with the service I'm talking to - the service is probably returning a 200 with an error code in JSON.
(re-frame/reg-event-db ::upload-to-heedy-success store-basket-interceptor
(fn [db [x response]]
(println "upload success " response)
(update-in db [:basket] dissoc response)
))
When it is set up this way with http-xhiro:
:on-success [::upload-to-heedy-success]
I get a response of "{:result ok}"
So either it's the backend that's to blame for a wrong code, or your code for not handling the response correctly (some APIs always respond with HTTP 200 but pass the error in the body). Both cases have nothing to do with re-frame.
But when I set it up this way:
:on-success [::upload-to-heedy-success date]
I get the date only
upload success 1701745448671
reg-event-db
without the trim-v
interceptor always passes the event ID as the first item of the second argument to the event handler. That would be x
in your example.
When you use [::upload-to-heedy-success]
, response
will indeed be the response.
When you use [::upload-to-heedy-success date]
, response
will always be date
since you don't destructure the vector to get its third item.
> These event vectors will be dispatched (`result` is conj
-ed to the end) making all encoded values AND the result
available to the handlers.
I don't see it talking about the response at all.
result
is probably the response, yes. But where does it say that whatever else you pass to the event vector will end up being a part of the result
value?
Even if it did say so, how could it possibly be true? Suppose the server answers with "hello"
- how can you make an arbitrary date
a part of that value?
The line quoted by you says explicitly: result
is conj
-ed to the end.
So if you specify :on-success
as [:evt]
, then on success (conj [:evt] response)
will be dispatched.
If you specify it as [:evt date]
, then (conj [:evt date] response)
will be dispatched.
Hmmm I kind of see. This worked:
(fn [db [_ date response]]
(println "upload success " date response)
Hey, I'd appreciate a sanity check re: using the right tool for the job. I have a piece of UI that persists across route changes. Its style changes based upon data in my app-db. But I have this weird off-by-one thing happening where the UI is in the +-1 state, i.e. if the route is page 2, the UI element is in its page 1 or page 3 state. I have tried everything I know of in the re-frame toolbox, which tells me the error lies within. I have this :on-click
handler:
(fn []
(when (<= 0 depth 4)
(dispatch [:update-parens-depth inc])
(dispatch [:routing/push-state route {:location @parens}])))
The parens subscription depends on the updated value of that first event, so predictably it lags behind. I tried a traditional reg-sub
with and without input signals, reg-sub-raw
, and a pair of effect handlers that make the appropriate changes. But @parens
is always behind or ahead a step. Is there a re-frame tool (or else a library) for ensuring order in a particular fashion?