Fork me on GitHub
#clojurescript
<
2020-07-16
>
lukasz15:07:29

What would be the best way of integrating a library written in Clojurescript with a typescript codebase (+ whatever comes with it, webpack, npm deps and the whole garbage pile)? Looks like shadow-cljs has a node-module target, but it's not 100% clear if that's what I'm looking for

lilactown15:07:41

you want the :npm-module target

lukasz16:07:04

I must have missed that option. That's perfect - thanks @lilactown

3
wombawomba17:07:23

Is anybody here using GraphQL? If so, what client are you using, and how’s it working out for you?

lilactown17:07:42

in the past I’ve wrapped apollo-client with great success

wombawomba17:07:37

Interesting. Any advice for if I were to try to go down that path?

lilactown18:07:40

just to wrap it in something nice - if you’re using React Hooks, it’s really simple to use react-apollo. last time we were using Reagent so we wrapped apollo-client in a reagent reaction which worked out pretty well

wombawomba18:07:38

alright, I’ll look into that, thanks

wombawomba18:07:21

I’m using Reagent/Re-frame but I’ve never tried making custom reactions

MagnusE18:07:28

What would be a good way of getting the results (header + code + body) from js/fetch into a map? I've not found any libraries that uses the fetch api, only XHR.. I'm trying

(let [obj (-> (js/fetch "")
                (.then (fn [x] x))
                (.catch "something went wrong..."))
        code (.-status obj)]
    {:obj obj
     :code code})
;=> {:obj #object[Promise [object Promise]], :code nil}
but the code should be 200, not nil. this works when I test the http api from the console, and the packets are identical when I look at them from the browser devtools. I'm kind of stuck, so I would appreciate any help

noisesmith18:07:48

that Promise is a handle to something that might eventually complete, I wouldn't expect it to have the response code from the server yet because it might not even have made the call when you capture the value you do

noisesmith18:07:31

I think you need to list the rest of your code into the .then of the promise, or use a library like core.async that lets you do the equivalent without it turning into a messy series of callbacks

noisesmith18:07:59

the function inside .then knows about the status code etc. the code outside it can't

noisesmith18:07:44

that method returns another Promise iirc, that you can chain another thing onto, etc.

MagnusE18:07:46

ooof. That's not very nice..

noisesmith18:07:52

it's a limitation that the js runtime imposes, the problem is that there's only one thread, and if code sat and waited for http responses everything on the page would be very very slow

noisesmith18:07:14

this mechanism is awkward but allows better performance (since you can't use more threads)

MagnusE18:07:58

I see. Too bad there is no one to copy from..

MagnusE20:07:38

I did not get it to work, but the cljs-ajax library does at least work with xhr

Lu21:07:31

@U017H3L9EHF Look if you don't wanna use that lib this is what you're supposed to do:

(let [obj (-> (js/fetch "")
              (.then (fn [x]
                       (prn (.-status x))
                       ;; needed to get the body out
                       (.text x)))
              (.then (fn [body]
                       ;; your logic must go in this callback, as you are
                       ;; certain that the body as been all streamed down.
                       (prn body))))])

3
delaguardo18:07:30

Hi, I have some problems with variadic args in multimethod. Trying to apply it to the list longer than 20 elements throws wrong arity exception https://gist.github.com/DeLaGuardo/548b6d0eee2c2d29e308d7ffc2c9d43c

delaguardo18:07:06

Looks like a compile bug for me because in clojure it works

dnolen18:07:26

probably an old one? it might actually be a dupe - but I would open issue with those multimethod details

dnolen18:07:56

can look later if it's a dupe and then copy over the multimethod case as something to test for when it gets fixed

knubie20:07:41

What’s the best way to detect when code is running in a test?

noisesmith20:07:19

it's better to have code that's parameterized by the test

phronmophobic20:07:37

what's the use case? if you're thinking about having code behave different during a test, then that's probably not a good idea

lilactown20:07:35

are you Volkswagen? :sleuth_or_spy::skin-tone-2:

🙂 3
😂 27
3
knubie21:07:02

@noisesmith @smith.adriane I want to turn off spec instrumentation when the tests are running

lilactown21:07:22

unstrument it while tests are running, instrument it after

noisesmith21:07:58

I think the cleaner option is not turning on instrumentation from normal code - there should be a top layer that conditionally invokes it

3