Fork me on GitHub
#clojurescript
<
2021-12-06
>
Richard Bowen05:12:43

Hey. What's a good library with ClojureScript for handling requests; GET, POST, PUT, etc..

borkdude10:12:06

I've been using that one for a long time and it hasn't disappointed me.

dvingo16:12:01

also venerable - https://github.com/funcool/httpurr which has node.js support, haven't found many libs that do

paulbutcher19:12:44

I’m getting a warning when compiling the following code:

cljs.core/-, all arguments must be numbers, got [#{js/clj-nil clj-nil} #{js/clj-nil clj-nil}] instead

  (- (ocall scale :invert translate-delta) (ocall scale :invert 0))
  ^---
I expected that I could fix it like this:
(- ^js/number (ocall scale :invert translate-delta) ^js/number (ocall scale :invert 0))
But that gives me exactly the same warning. What am I missing?

sun-one20:12:38

Are you sure that these calls are returning numbers (ocall scale :invert translate-delta) (ocall scale :invert 0) based on warning it seems like they're returning nil instead.

sun-one20:12:36

Or w/e {js/clj-nil clj-nil} is (which doesn't appear to be a number).

dpsutton20:12:14

I don't believe this is based on runtime values. This is the cljs compiler thinking these functions return nil (and maybe they do but this is metadata and tags based)

paulbutcher20:12:54

They definitely return numbers. The code works perfectly. But I'd like to be warning clean if possible?

paulbutcher20:12:41

(The functions, BTW, are from Vega).

dpsutton20:12:23

are you on a recent or most recent ClojureScript?

cjohansen21:12:50

If I evaluate (type {}) I see cljs.core/PersistentArrayMap. Is there some way to get that symbol from a value? (str (type {})) returns the function’s toString from what I can tell, there is no meta, and (.-name (type {})) returns an empty string. Other things I can do?

p-himik21:12:46

Just in case - why do you want to do that?

cjohansen21:12:10

I’m working on some developer tooling 🙃

p-himik21:12:31

(pr-str (type {}))

p-himik21:12:58

(no clue whether it'll work in an optimized build)

cjohansen21:12:54

ah, of course, why didn’t I think of that :man-facepalming:

cjohansen21:12:56

thanks!

👍 1
cjohansen21:12:22

optimized build is not highly relevant for this, but I’ll remember to look into it

borkdude22:12:07

If it interests anybody, I got a CLJS pREPL working inside JVM unit tests so you can eval CLJS expressions while testing from the JVM. This is useful for the cljs-math lib to compare Node.js results to the JVM results. https://github.com/quoll/cljs-math/blob/baf0a46781ca4cd5d0b0d85977141de58a9bf4f8/test/cljs/math/test_prepl.clj#L33-L46

1
👍 1
thheller06:12:17

you don't need sockets really. can just setup streams directly and skip all the network stuff

borkdude07:12:40

I basically copied something from the babashka tests which also has a prepl and reused that

paulbutcher23:12:11

@dpsutton this is with 1.10.893.

dpsutton23:12:04

to diagnose, if you replace the call sites with (or (ocall scale ...) 0) does the warning go away?

paulbutcher23:12:18

Yes, that does make it go away.

dpsutton23:12:33

Then i think it is a bug in the type inference going on. You can use this or hack, or I think there’s a way to turn off particular warnings. You could also create an issue on http://ask.clojure.org, ideally with a minimum reproduction. Simple deps.edn, with that single dep, or ideally just copy the functionality that recreates the issue, and keep removing extraneous bits until a simple reproduction exists

paulbutcher23:12:09

Cool. Will do 👍 Thanks!