Fork me on GitHub
#helix
<
2022-06-08
>
geraldodev21:06:48

How do you fellow helixers fetch on the browser ? Do you use js/fetch or its wrapper https://github.com/lambdaisland/fetch or something else.

dominicm22:06:47

I use js/fetch

geraldodev22:06:13

@U09LZR36F Do you use a library for promises ?

geraldodev23:06:46

No I remember: lambdaisland pulls kitchen-async which pulls core-async which is on hold for https://www.juxt.pro/radar 2021

dominicm02:06:34

I don't. I'm passing the JSON as a JavaScript object around

geraldodev14:06:34

promesa looks well written/behaved wrapper. No dependencies, documentation.

Brandon Stubbs14:06:27

Yeah, I trust most of the funcool libs, they are battle tested in https://github.com/penpot/penpot

geraldodev23:06:26

@U015Y1A1N8Y Didn't knew about this project. Thank you for pointing it.

💙 1
geraldodev18:06:18

https://github.com/lambdaisland/fetch/blob/main/src/lambdaisland/fetch.cljs#L106 this p/try block from kitchen-async has no equivalent on promesa, so i changed the p/let inside the p/try to . That proves @U09LZR36F point, native .then and .catch are more than enough for operations. I'm using p/promise constructor on decode-body in case the implementation (its a multi-method) does not give a promise back.

geraldodev18:06:02

the fetch operation https://github.com/lambdaisland/fetch/blob/main/src/lambdaisland/fetch.cljs#L105 is not being guarded by the p/try block, which opens the door to something wrong with it. the p/let block captures a response, the fetch api says it does not reject on 404 errors. it only rejects on network errors. the next promise operation is https://github.com/lambdaisland/fetch/blob/main/src/lambdaisland/fetch.cljs#L113 decode-body. I wonder how the https://github.com/athos/kitchen-async/blob/master/src/kitchen_async/promise.cljc#L126 p/try from kitchen-async is able to intercept rejected promises on the code. I know the code is there but my brain is not lispy enough to understand how. Is it really feasible ? because the native promise handling is dependent on chainning, and I think promises are different from exceptions semantically.

geraldodev00:06:29

despite the kitchen-async dependency pulling core.async, I liked lambdaisland.fetch. It pairs with muuntanja at server side, which responds to content-type. It defaults to asking for transit content, and has multi-methods to decode body based on the content-type.