Hi all,
I am using https://github.com/day8/re-frame-http-fx in my full stack clojure app (web and react native) using figwheel for the hot reloading.
re-frame-http-fx and so the underlying cljs-ajax work fine in react with the uri as a relative path such as
{:http-xhrio {:uri "/pages/all"} ... }
However, when I try to use it in my react native frontend, all the exact same :http-xhrio works as expected but I have to use an absolute path uri instead such as:
{:http-xhrio {:uri ""} ... }
For web or mobile, I used fighweel with the embed ring server option on the default port 9500
How can I use the format "/pages/all" for mobile as well? I tried on ios with the Xcode simulator
You can find the http-xhrio for the web https://github.com/skydread1/flybot.sg/blob/master/client/web/src/flybot/client/web/core/db/event.cljs#L26 and the http-xhrio for mobile https://github.com/skydread1/flybot.sg/blob/master/client/mobile/src/flybot/client/mobile/core/db/event.cljs#L16
Thank youI am confused, re-frame-http-xhrio works from react native at all?
Since cljs-ajax doesn’t use fetch I thought this wasn’t possible
https://github.com/day8/re-frame-http-fx/issues/23
It’s really simple to write your own fx, it’s only about 10 LOC: https://increasinglyfunctional.com/2019/06/25/http-fx-for-re-frame-on-react-native.html
That’s pretty cool - I will remember this next time
thx!
@joshmiller Thank you for the clarification regarding the difference between web and mobile URIs shapes.
I ended up using the google closure compiler option :https://clojurescript.org/reference/compiler-options#closure-defines which I can easily override with https://figwheel.org/docs/compile_config.html.
Then my uri is just (str BASE-URI /pages/all) with BASE-URI being defines as (goog-define BASE-URI "")
So it works for web and mobile but also dev and prod as well.
I’m not sure that would ever work, because in an app you aren’t “on a page” where a relative path would make sense, right? On the mobile web, you are on a web page that the browser can use to construct an absolute path from a relative path, but in an app you aren’t on anything.
What you could do is write a custom cofx that would automatically do it for you, so you’d have :localhost-http-xhrio { :uri "/pages/all" } that would construct the url and pass it along to the normal http-xhrio cofx.