clojurescript 2024-11-29

is there any reason to use cljs-ajax ie. goog.net.XhrIO rather than fetch (either directly via js interop or via a cljs wrapper)?

heh, people were wondering about XhrIO already in 2018: https://github.com/JulianBirch/cljs-ajax/issues/204

I'd only use fetch these days, via plain interop. no wrappers.

👍 2

yeah that's what I've done previously. I'm looking at a project now that's using re-frame-http-fx, which uses cljs-ajax and I started wondering...

well that is different. fx are still a useful abstraction. doesn't warrant bringing in cljs-ajax though. dunno if a library exists that just uses fetch instead?

Yes, there's one, by one of the guys from Day8 if I'm not mistaken.

I'm probably just going to write my own effect using fetch, since I want to bundle in some app-specific behaviour (like 401 handling etc)

one important difference is that unlike Fetch, XHR supports progress tracking https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/progress_event

It's possible with fetch as well, but it's definitely more cumbersome.