Fork me on GitHub
#clojurescript
<
2020-04-03
>
Spaceman00:04:49

how to convert an input stream to a blob? I have the following code: (go (let [response (<! (http/get (str url "/run-segmentation"))) file-reader (js/FileReader.) ] (set! (.-onload file-reader) (fn [e] (let [data-url (-> e .-target .-result)] (prn "data-url is " data-url) ))) (.readAsDataURL file-reader (:body response)))) And I want to readAsDataURL the input stream in the body

victorb09:04:27

you're running this in the browser right? What type of data is http/get actually returning?

victorb09:04:07

like you're not be able to get an input-stream as you would in JVM Clojure, as there is AFAIK no streams yet in browsers. So my guess is that you're getting either a string, buffer or blob directly there

Spaceman00:04:18

but I get the error that (:body response) isn't a blob

Spaceman00:04:23

How do I convert an input stream to a blob or a data url?

Nikolas Pafitis09:04:30

Hello guys, i can't seem to get cljs-http to send the request how i want it. I want to send a GET request with an edn content-type, doing so from postman works just fine, but doing it through cljs-http comes off different in my api

Nikolas Pafitis09:04:55

When i use cljs-http params in my api come off as {}

hindol09:04:21

Can you post the request code?

Nikolas Pafitis10:04:41

i changed it to post request instead of get and it works just fine

Nikolas Pafitis10:04:53

i just can't seem to find a way with cljs-http to send a body

hindol10:04:01

GET cannot have a body anyway.

hindol10:04:15

Did you find how to do it for POST?

victorb10:04:54

I'm fairly certain you only want to use content-type header when doing requests that normally have a body (so like POST, PUT and alike [even if technically you can send a body with a GET request, it's normally avoided]). Instead, take a look at the Accept header for signal to the backend what content the client can use

victorb10:04:34

@UJRDALZA5 nitpick but worth sharing anyways: GET can have a body, obviously a bad pattern as servers usually won't support it and no one expects that, but some backends, especially when they support large query parameters, also accept a GET with parameters for sending larger set of parameters. I think ElasticSearch is one of the more famous software that supports sending data in the body of a GET request

hindol10:04:57

Huh! Did not know this. Learning something new everyday. Thanks for that.

victorb10:04:39

🙂 Conclusion last time I read the http spec is that while you can send body in a GET request, the server should ignore it so it's not that useful, but then again we have the real world not giving two cents about specs 😛

Nikolas Pafitis13:04:49

Yes GET does support sending a body, and you can do it through postman, But i guess cljs-http does not allow that. So i switched my endpoint to POST

ak-coram14:04:06

I'm trying to use the cljs.analyzer.api to search the namespaces of my project for keyword constants, but it's tripping up on the external JS dependencies of my CLJS dependencies (react & reagent in this case: No such namespace: react, could not locate react.cljs, react.cljc, or JavaScript source). I'm thinking I probably need to setup a compiler environment before calling analyze-file on my sources, but I'm not entirely sure how that can be done (or if it's even the issue in the first place). Does anyone have experience running cljs.analyzer on their own sources? I also have figwheel-main up and running, so maybe I could reuse the compiler environment from their repl.

dnolen14:04:43

@ak407 what do you mean by external dependencies? might want to move this conversation over to #cljs-dev

ak-coram14:04:46

thanks, will do

Brandon Olivier22:04:33

I'm working with a third party JS lib, and a lot of the conversion of React components is tedious/hard to read. Is there a simple way to output (def formatted-name (adapt-react-class lib/FormattedName)? Ideally, I'd just start from a list with "FormattedName"

lilactown22:04:41

@brandon149 I’m not sure what you mean - what do you want to use formatted-name for?

Brandon Olivier22:04:20

I need to run def so that I can use those third party react components as reagent components (ie. with hiccup syntax)

Brandon Olivier22:04:29

I want to export it from a ns

lilactown22:04:10

oh, I see. you want to take a list of components and emit defs for each of them?

dpsutton22:04:10

Ideally hiding the fact that they are react components rather than reagent components?

Brandon Olivier22:04:55

That is exactly right

Brandon Olivier22:04:21

I can do it pretty trivially for just 1, but I'd like to apply it to a whole list of components

lilactown22:04:48

well, heads up - it’s hard to ignore completely that things are not reagent components. sometimes it’s better to embrace the interop…

lilactown22:04:02

but for getting rid of some of the boilerplate, macros can help a bit

Brandon Olivier22:04:06

My primary concern is using adapt-react-class to use them at all. I'd like to just have that all in one place

lilactown23:04:54

something like…. in my_app/some_lib.clj

(ns my-app.some-lib)

(defn camel->kebab
  [sym]
  ,,,)

(defmacro gen-defs
  [prefix component-names]
  `(do
     ~@(for [component component-names]
         `(def ~(camel->kebab component)
            (reagent.core/adapt-react-class
             ~(symbol prefix component))))))
in my_app/some_lib.cljs
(ns my-app.some-lib
  (:require
   ["some-lib" :as some-lib])
  (:require-macros [my-app.some-lib :refer [gen-defs]))

(gen-defs
 some-lib
 [FormattedName])

Brandon Olivier23:04:42

I tried something similar (now exact, cause I like your api more) and what happens when I load the page is that the components aren't available for some reason

Brandon Olivier23:04:55

Those components don't show up until after the ns that has those definitions is live reloaded (I'm using shadow-cljs)

lilactown23:04:27

not sure, maybe try restarting shadow-cljs?

Brandon Olivier23:04:59

I'll try that. It's weird, I logged some values, and they're all undefined until I save that file. It must be evaluating differently in those contexts, right?

lilactown23:04:29

it might be some caching that shadow-cljs is doing

lilactown23:04:51

I’m not really sure what the order of operations you’re doing are