Fork me on GitHub
#clojurescript
<
2018-01-10
>
xiongtx01:01:34

I’m getting a reader error w/ the ##Inf tag in cljs:

Compile sources, elapsed time: 1069.79432 msecs
clojure.lang.ExceptionInfo: failed compiling file:resources/test/env/test/cljs/core.cljs {:file #object[java.io.File 0x52c46116 "resources/test/env/test/cljs/core.cljs"]}
	at clojure.core$ex_info.invokeStatic(core.clj:4739)
...
Caused by: clojure.lang.ExceptionInfo: No reader function for tag Inf {:type :reader-exception, :line 988, :column 14, :file "file:/Users/tianxiang.xiong/.m2/repository/org/clojure/clojurescript/1.9.946/clojurescript-1.9.946.jar!/cljs/core.cljs"}
...
Even though I have an explicit dependency on tools.reader 1.1.1, as lein deps :tree confirms. Anyone else encounter this problem?

qqq07:01:59

how does

(. js/console log (str ::foobar))
work correctly given that cljs has no notion of namespaces ?

mikethompson07:01:47

The js namespace is given special treatment

qqq08:01:12

let me rephrase why does ::foobar resolve correclty into some.name.space/foobar given cljs has no notion of namespaces

carkh08:01:13

it certainly does have this notion at compile time

qqq08:01:02

what is something that I can do with 'notion of namepsace ar runtime' that I can not do with 'notion of namespace at compiletime' ? calling ns-resolve ?

carkh08:01:28

i never much investigated runtime ns support, it only makes sense that we couldn't even compile a project without that notion at compile time

carkh08:01:27

just like you said ... ::foobar is resolved

cmal11:01:16

Hi, does anyone use clojurescript with d3? I found d3 do some not immutable operations like in this example: https://bl.ocks.org/mbostock/3883245 x.domain(d3.extent(data, function(d) { return d.date; })); set x Axis's domain, I am working on a project which need to do some similiar work. I found there are some errors prevents generating the axis. How this can be achieved in clojurescript?

thheller11:01:37

@cmal d3 only supports JS objects/arrays. if you pass a clojure vector or so as data that won’t work

cmal11:01:34

OK. I translated that, using clj->js.

cmal11:01:54

I'll paste some code.

thheller11:01:06

line #5 is passing a clojure vector to a d3 fn

cmal11:01:17

and then use (dividend-y) again to retrieve the y axis.

tomaas11:01:27

if case you use charts, this lib is awesome abstraction on d3

cmal11:01:36

I will change that!

thheller11:01:17

don’t need the ^js annotations in lines 14,15,10 if you do it in line 8, probably need it on (fn [^js d] (.-div...)) though

cmal11:01:48

@thheller OK. Am I right about the (dividend-x-set-domain ^js data)? I am wondering whether should I use the previous (dividend-x) or (dividend-x-set-domain ^js data)'s return value when do something like js's .call(d3.axisBottom(x)).

thheller11:01:53

but they don’t hurt either its fine 😉

thheller11:01:24

you only need the ^js tag an anything that does JS interop at places where the interop actually occurs

thheller11:01:31

so no that call doesn’t need it

cmal11:01:01

OK. :thumbsup:

cmal11:01:09

@thheller Should I use clj->js in (.axisLeft d3 (clj->js (dividend-y))) when passing a function to some d3 method like .axisLeft? (dividend-y defined just likes before.)

thheller11:01:49

no that already returns a d3 object

cmal11:01:04

OK. THANK YOU!

cmal11:01:24

And should I wrap fn in clj-js in

(def dividend-line
  (-> d3
      .line
      (.x (fn [^js d] ((dividend-x) (parse-time (.-date d)))))
      (.y (fn [^js d] ((dividend-y) (.-divirate d))))))
?

thheller12:01:27

I don’t understand the question. You only need to call clj->js whenever you have a CLJS object but want a JS object, never when you already have a JS Object

thheller12:01:10

when you call a d3 fn you never get a CLJS object back so you never need to call clj->js on any of these

thheller12:01:32

depending on how many JS objects you use you may be better of only using JS objects as well.

cmal12:01:38

I thought the (fn [^js d] ((dividend-x) (parse-time (.-date d))) is not called when passed to d3.line.x(). So should wrap in a clj->js? 😕

thheller12:01:41

the conversion is quite costly

thheller12:01:50

I don’t understand sorry, but no (clj->js (fn [...] ...)) is never required

cmal12:01:14

Thank you very much. 🍻

tomaas12:01:08

Hi, we've just noticed that that app.js compiled for production has snippets of code that are not minimized (libs like moment.js, react-dom from http://cljsjs.github.io).

gklijs12:01:03

Do you import them as externs, or as npm-dependencies?

tomaas12:01:20

cljsjs libs already do that

tomaas12:01:50

it just about not renaming the vars of those external libs

thheller12:01:54

cljsjs is always included as-is, no processing is done of any kind

tomaas12:01:06

i thought production build takes away comments, and also minimizes

thheller12:01:46

cljsjs typically ships a :file-min which is the already minified code

thheller12:01:54

comments are usually there for licences and stuff

tomaas12:01:16

from here I understand that those libs get through the stage of google closure compiler

thheller12:01:53

no, your code goes through the compiler and it needs to know what the foreign libs do

thheller12:01:07

the foreign libs themselves are never touched

tomaas12:01:18

ok, thanks

rnagpal16:01:10

I am using haslett for websockets. When I try to connect to a WS endpoint which throws 500 I get an error at this line (js/WebSocket. url) Error is expected in this scenario. But I am not able to catch this error. I tried

(try (ws/connect url)
                               (catch :default e
                                 (js/console.log "Failed to connect to ws! " e)))
and
(try (ws/connect url)
                               (catch js/Object e
                                 (js/console.log "Failed to connect to ws! " e)))
None of these two catch the error

thheller16:01:48

@rnagpal JS is pretty much all async, you probably want to listen to the error event

rnagpal16:01:15

yeah this is wrapped in go block

rnagpal16:01:32

@thheller but how does that impact the catching of error

thheller16:01:56

well the code needs to throw in the first place which it probably doesn’t

rnagpal16:01:36

I see the error in console, so the Javascript is natively throwing it

jrheard16:01:27

if i’m writing a blog post targeted at people who don’t know clojure/script, and i’ve got these sentences (among others) in the beginning of my clojurescript section: ClojureScript is a dialect of Clojure that compiles to JavaScript. ClojureScript lets you write a Clojure program and then run it in a web browser. is that second sentence fine, or is it misleading/inaccurate somehow?

jrheard16:01:57

i originally qualified it with “ClojureScript essentially lets you write a Clojure program and then run it in a web browser”, but removed the “essentially” because i didn’t like how it looked. should i add it back, or is the sentence fine without it?

dnolen16:01:13

@jrheard it’s not really about browsers (though that’s a major usecase), it’s about running where JavaScript can run (i.e. where JVM isn’t viable or less suited for some reason)

jrheard16:01:01

good point david, i’ll make sure to point that out!

jrheard16:01:12

thanks 🙂

joshkh16:01:06

do you folks have a favourite news source for clojure(script) related blog posts?

joshkh16:01:35

thanks! and what a soothing page...

justinlee17:01:46

@rnagpal That catch should work (and the websocket library definitely throws exceptions and haslett doesn’t seem to catch them for you unfortunately). Are you sure that’s the right line? You said in your comment that the exception was being thrown on (js/WebSocket. url) but then you showed a try block around (ws/connect url)

jindrichm20:01:06

The :npm-deps story (https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules) doesn't seem to be complete. Is there a more complete tutorial, perhaps for lein-cljsbuild/figwheel?

souenzzo20:01:08

I'm also looking for it

rnagpal21:01:16

@lee.justin.m Thanks for the reply. Actually I was wrong. Javascript doest throw an error when we get 500 on WS connect URL

rnagpal21:01:30

so we do need to add onerror listener

justinlee21:01:13

really? you shouldn’t. i’m pretty sure the websocket interface promises to call onclose whenever onerror is called, even on connection failure

rnagpal21:01:55

onerror does give the error

justinlee21:01:56

onclose should too. so you should be able to look at code and reason in the promise chan returned by haslett

rnagpal21:01:09

@lee.justin.m thanks. You are correct. That is called too