Fork me on GitHub
#off-topic
<
2020-07-17
>
Drew Verlee17:07:31

I associate then with the idea of asynchronis handling. So in the example below the first where i pass a fn to turn a response into json response makes sense.

fetch('')
  .then(response => response.json())
  .then(data => console.log(data));
However, the second call to then, to just to log seems odd. This shouldn't be async. Is this example just misleading in its usecase or is there something else going on here?

Drew Verlee17:07:02

i guess i is separated in time from the first thing. and given you need a catch it also flattens the logic out.

noisesmith17:07:21

repeating a commonly known prefix is less noisy compared to nesting various kinds of forms to some? yeah it looks silly to me too

noisesmith17:07:53

it's almost like an unrolled monad - simplifying the thing by putting every step in the same container

noisesmith17:07:03

(simplified for human readers taht is)

Drew Verlee17:07:49

Right i guess the main concern is avoiding nesting. i guess my first step function could do everything. But i ended up copying the pattern i saw and only later questioned it.

noisesmith17:07:43

right, but the criteria for nesting here isn't a technical constraint, it's a human reader concern

noisesmith17:07:24

predictable patterns are a great way to make bugs visible 99.5% of the time and impossible to see 0.5% of the time

noisesmith17:07:14

especially because using redundancy for clarity increases the chances of accidentally correct reading of what the code does (that leads to a totally incorrect refactor)

lilactown17:07:39

@drewverlee it’s because fetch resolves the promise as soon as headers come in, which means that the response might not be fully complete yet

‼️ 6
lilactown17:07:10

so in this case response.json() returns a promise that resolves once the body is fully available

Drew Verlee17:07:42

i see. This makes sense with what i'm seeing. i tried to make it one step and it failed.

Drew Verlee17:07:52

this is probably clear in the docs and im reading past it, thank you.

lilactown18:07:56

yeah, the API is clearer when you want to do something other than consume json. like stream a binary blob

Drew Verlee18:07:41

i guess i picked it because it was "modern" and included. Maybe there is something more tailored for clojurescript http requests?

lilactown18:07:35

I think fetch is quite good when used in conjunction with CLJS

lilactown18:07:56

no matter what, you’re going to have to deal with async-ness of the request. raw AJAX requires using callbacks. fetch gives you a promise interface, which for a lot of use cases is easier IMO

lilactown18:07:47

there’s cljs-http which gives you a core.async interface if you’re already use core.async

andy.fingerhut20:07:25

Not trying to promote Facebook or anything here -- just already have the pics and a Wikipedia link posted on my page here of a cool thing I noticed in my freezer today: https://www.facebook.com/andy.fingerhut/posts/3239965412693392

3
andy.fingerhut20:07:39

Guess I can just put a photo here directly. This ice tray had no special preparation -- just filled it with tap water from kitchen sink and put into my freezer. It hasn't done this before.

👀 3
❄️ 3
seancorfield20:07:49

It's aliiiiiive! 🙂

seancorfield20:07:29

Also, I don't think you made that post public -- so only your FB friends can see it anyway "This Content Isn't Available Right Now"

borkdude21:07:55

Yes, can't see it

andy.fingerhut00:07:04

My wife found there is an article on “ice spikes” on Wikipedia that looks like this phenomena

Mno13:07:52

There’s a SciShow video that explains it in relatively simple terms lemme see if I can find it.

Mno13:07:35

https://www.youtube.com/watch?v=b9a36vsQh80 It’s the first thing they explain so it starts at around 45 seconds

sogaiu00:07:48

a bit frantic in pace due to editing(?), but neat stuff!