Fork me on GitHub
#clojurescript
<
2021-08-23
>
Schpaa12:08:06

So, (get {26 {:a 1}} 26) should return nil, right?

p-himik12:08:17

No. Why do you think that?

Schpaa12:08:31

Well, thats what it does

Schpaa12:08:46

I would think it would return {:a 1} of course, but no

p-himik12:08:00

Need more details because that's exactly what I see on my end in a NodeJS-based REPL:

cljs.user=> (get {26 {:a 1}} 26)
{:a 1}

Schpaa12:08:25

Look, of course

Schpaa12:08:33

I just dont get it

p-himik12:08:52

So, the needed details: • Platform • CLJS version • A confirmation that that get is indeed cljs.core/get and not some other function • A minimal reproducible example, ideally

p-himik12:08:13

You can also just find that code in the compiled JS and see what's going on exactly, without having to guess.

Schpaa12:08:27

Well (get {26 {:a 1}} 26) does what it should

Schpaa12:08:42

but not with some return of a function

p-himik12:08:05

What do you mean by that?

Schpaa12:08:06

the function returns a map that looks like {26 … etc}. I put it in an atom and check for (get @restult 26) and it returns nil

Schpaa12:08:30

I deref the atom and it gives me {26 {:a 1}}

Schpaa12:08:04

the types of the keys are numbers

Schpaa12:08:19

there is nothing obviously wrong as I understand it

p-himik12:08:26

Do you deref and print it right there along with get or do you do that some time later? If so, it might be some hard to debug timing issue.

Schpaa12:08:55

I was just

(defonce r (atom nil))

Schpaa12:08:09

and reset! it in the code, and then deref’ed it later

Schpaa12:08:23

so I dont think this is a timing issue

p-himik12:08:49

Sounds like there are many more moving parts than a plain text explanation would cover. Please create an MRE.

Schpaa12:08:01

Yeah, I’ll check into it

Schpaa12:08:11

If I do a (let [a (into {} @r)] (get a 26))

Schpaa12:08:18

It works, so @r is def. not a map

Schpaa12:08:06

and that was it -> a sorted-map

p-himik12:08:23

> It works, so @r is def. not a map Huh, why?

cljs.user=> (into {} {:a 1})
{:a 1}

p-himik12:08:14

Still no idea what you mean, given that

cljs.user=> (get (sorted-map 26 {:a 1}) 26)
{:a 1}
But if you got it resolved, then great.

Schpaa12:08:16

suprised me too

Schpaa12:08:36

first time I’ve experienced this

p-himik12:08:08

I'm 80% certain you're doing something strange and that's not a problem with CLJS. :)

Schpaa12:08:23

of course, I just need to make sense of “some” of it

👍 2
Schpaa12:08:30

so I have some leads

Schpaa12:08:47

I am 100% sure this is my wrong doing, not cljs 🙂

Schpaa13:08:34

I used sorted-map-by with an invalid function

Schpaa13:08:08

But damn how confusing it is when the repl-output has the appearance of a map or whatever, when it is not

Schpaa13:08:58

MRE:

(let [a (into (sorted-map-by :id) {26 {:a 1}})]
  [a (get a 26) (map? a)])

dazld13:08:36

Do any of you have a (obviously very subjective) favourite library for wrapping promises? I know about core.async's rather spectacular <p! https://clojurescript.org/guides/promise-interop#using-promises-with-core-async - wondering what else might be out there.

dazld14:08:10

am investigating promesa - looking like a solid alternative.

👍 2
Derek14:08:58

kitchen-async is (was?) popular https://github.com/athos/kitchen-async

💯 1
niwinz07:08:26

Here promesa author, we are using it extensively in relatively big projects like penpot among others. If you have any issue, feel free to ask.

👍 5
mbjarland14:08:10

I have a question, does something similar to codepen for javascript/react exist for clojurescript/react. I.e. in codepen, I can (as described in the react tutorial) code the html, css, and javasript for a small app and see the changes and console live in the right hand window. Useful for a purely "in the browser" programming experience and getting to try a toolset quickly without installs etc.

zendevil.eth15:08:46

what’s the best way to make ipfs requests from clojurescript?

zendevil.eth15:08:11

cljs-http returns cors error for my ipfs endpoint

p-himik15:08:59

Is it your own endpoint?

zendevil.eth15:08:41

no it’s public ipfs

p-himik15:08:59

If I remember CORS correctly, it sounds like they don't want you to use it for your own website. At least, not from a browser, since it doesn't specify the right headers to allow your browser to access it.

p-himik15:08:46

So either find another endpoint or find a JS client that you could use via interop.

p-himik15:08:53

And looks like IPFS itself might have something to do with it: https://docs.ipfs.io/how-to/address-ipfs-on-web/#path-gateway