Fork me on GitHub
#clojurescript
<
2020-06-29
>
Chris McCormick08:06:47

what should the content-type of a .cljs file be? application/clojurescript?

p-himik08:06:31

Probably text/clojurescript.

p-himik08:06:50

But of course neither is known by IANA, so usefulness of such media types would be limited.

Chris McCormick08:06:02

js is application/javascript but maybe it depends on the context, as js is explicitly supposed to be executed in the browser.

Chris McCormick08:06:17

(it used to be text/javascript )

p-himik08:06:50

Vice versa, I think. According to MDN: "Per the HTML specification, JavaScript files should always be served using the MIME type text/javascript"

p-himik08:06:24

"Even though any given user agent may support any or all of these, you should only use text/javascript. It's the only MIME type guaranteed to work now and into the future."

p-himik08:06:57

Which makes sense, given that application is more generic and is intended to be used for binary data.

Chris McCormick09:06:48

ah good, thanks for this!

Sung09:06:53

When compiling a self-hosted clojurescript program with several macros, the compiler spams me with messages starting with

WARNING: Use of undeclared Var cljs....
Should I be concerned?

mfikes12:06:39

@skwak22 That's not normal with self-hosted ClojureScript and macros FWIW, so it is probably worth getting to the bottom of that IMHO.

Sung13:06:22

thank you!

MorongÖa12:06:59

I have converted a `js` object to `clj` using (js->clj obj). This is what I get back: `{"foo" nil, "bar" #object[com$core$test]}` . How do I get the value of foo and bar?

Roman Liutikov13:06:46

(js->clj v : keywordize-keys true)

MorongÖa02:06:37

👍:skin-tone-4:. Thanks

Shreyanshi Bharadia13:06:13

Can someone suggest me a good Mark Down Editor which can be easily integrated with cljs? If possible can you give me some examples also about how to use it. A bit new to Clojure.

Eric Scott14:06:38

Hi, Is this expected behavior?

cljs.user=> (def p (promise))
WARNING: Use of undeclared Var cljs.user/promise at line 1 <cljs repl>
Execution error (TypeError) at (<cljs repl>:1).
Cannot read property 'call' of undefined

dnolen14:06:35

yes, promise isn't portable

dnolen14:06:15

none of the constructs that assuming multithreading exist (yet) in ClojureScript

Eric Scott14:06:13

Ah. OK. Thanks!

Casey15:06:08

You can access the Promise constructor with js/Promise , more info at https://clojurescript.org/guides/promise-interop

dnolen16:06:32

but note that Clojure promise and JavaScript Promise are different things

stefan17:06:56

I’m trying to copy text to clipboard from a cljs app, but I’m getting undefined on (js/navigator .-clipboard) . Am I trying to access this incorrectly?

stefan17:06:30

wanting to call navigator.clipboard.writeText()

lukasz17:06:25

It's the other way around (.writeText (.-clipboard js/navigator) "foo")

lukasz17:06:50

You might need to use .-writeText

stefan17:06:54

sorry I fogot the thread operator, I am calling in that order I believe

stefan17:06:50

here n returns the navigator, but the 2nd part of the console log returns undefined

noisesmith17:06:20

-> is not an operator for all x (-> x) is identical to x

stefan17:06:47

you’re right I don’t need that, I’m just moving things around. dropping the -> gives the same result

lukasz17:06:47

Don't have the cljs repl handy, but there's multiple things here: writeText returns a promise and also requires a permission from the user. So in theory your code should look something like this (-> js/navigator .-clpboard (.-writeText "foo") (.-then (fn [e] (.log js/console e))

stefan17:06:23

So this is what I see in the console when running (-> js/navigator .-clipboard (.writeText "foobar"))

stefan17:06:29

TypeError: undefined is not an object (evaluating 'navigator.hi.Qi')

noisesmith17:06:53

you spelled clpboard differently than the example

stefan18:06:37

I think it was typo, the property name is clipboard

stefan18:06:40

It seems to just be clipboard. When I print the js/navigator object there are other keys such as language languages , clipboard etc.

stefan18:06:03

But (js/console.log (-> js/navigator .-languages) (-> js/navigator .-clipboard)) returns the languages and clipboard is undefined

stefan18:06:58

Thanks but I don’t think it’s a compatibility issue, it’s only unavailable in ie

noisesmith18:06:51

yeah - I was just "sharing my work" that I checked that

stefan19:06:05

I think this error TypeError: undefined is not an object (evaluating 'navigator.hi.Qi') is telling me that clipboard and writeText are being renamed. Trying to figure out why that is.

phronmophobic19:06:14

variables will get renamed under advanced compilation

phronmophobic19:06:00

you may be able to do the following:

(def write-text
  (-> js/navigator
      (goog.object/get "clipboard")
      (goog.object/get "writeText")))
(write-text "foobar")

phronmophobic19:06:19

you may have to require goog.object

stefan19:06:31

thanks, will try this out

stefan21:06:33

Was able to finally call writeText using the above (thank you), but got an illegal invocation error 😕. I guess I need to find out why (-> js/navigator .-any-other-property) seems to work but (-> js/navigator .-clipboard) is undefined (I’m assuming because of the rename).

stefan21:06:55

This is a guess but I think maybe there is a whitelist of properties that don’t get renamed at compile time, and clipboard needs to be added. Not familiar enough with the compilation process though

phronmophobic21:06:34

you can whitelist properties using externs, https://clojurescript.org/guides/externs

phronmophobic21:06:49

but that doesn't seem like it would fix the Illegal Invocation error

phronmophobic21:06:59

it seems like the Illegal Invocation has something to do with the this binding for the function

phronmophobic21:06:41

maybe something like:

(def clipboard
  (-> js/navigator
      (goog.object/get "clipboard")))
(def write-text (.bind (goog.object/get clipboard "writeText")
                       clipboard))

stefan21:06:56

that was it!

stefan21:06:19

thank you!

👍 3
dominicm08:06:49

You're right that there's a whitelist, it's in Google closure itself I believe

👍 3
cap10morgan20:06:57

Having some trouble generalizing the new webpack support from the react example. What would the require and usage look like for a library like sjcl, for example: https://stackoverflow.com/questions/16752924/good-stanford-javascript-crypto-library-sjcl-examples-js-cryptography ?

cap10morgan20:06:00

hmm... never mind. I think I was overcomplicating it. seems to be working the way I (should have) expected.