Fork me on GitHub
#clojurescript
<
2018-03-23
>
qqq01:03:20

how do I use modulo (%) from cljs ?

mfikes01:03:08

mod or rem

👍 4
mfikes01:03:30

there is also js-mod if that's what you are really after

mfikes01:03:37

For example (js-mod 5 3) literally get compiled to 5 % 3

pablore01:03:34

Hi, how could I trace or debug errors shown in the browser? I'm using figwheel

pablore01:03:04

In particular this is the error im having: Error: Var clojure.test.check.generators/simple-type-printable does not exist, clojure.test.check.generators never required

mfikes02:03:12

@pablore I’d first check to see if you have [org.clojure/test.check "0.9.0"] as a dependency. If you are using the cljs.spec.test.alpha namespace it will attempt to dynamically load test.check

pablore02:03:03

I have it but only as a dev dep sice Im only using it on tests

mfikes03:03:33

@pablore I wonder if Figwheel is just showing the error, but if it is still possible to take a look at *e in the REPL. If so, the stacktrace might give a clue.

mfikes03:03:32

You are definitely seeing a dynamic loading failure related to spec and test check. (This code is triggering https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/spec/gen/alpha.cljc#L29)

😮 4
qqq09:03:55

basic question: how do I do (js/console.log (slurp "fmd.json")) properly in cljs? Basically I want to read json data from a URL. Do I need to formally make a GET request of some form?

thheller09:03:46

yes, request it.

qqq09:03:13

Got that part working. In Clojure, I can read json via: [clojure.data.json :as json] json/read-str however, clojure.data.json does not appear to exist in cljs How do I do "str -> json" in cljs ?

qqq09:03:31

or rather, how do I do "str encoding json data -> clj"

thheller09:03:25

(js/JSON.parse the-str), js->clj to convert to clojure data

qqq09:03:34

@thheller: got it; thanks random aside: apparently clojure.data.json/read-str is OKAY with trailing commas, whereas JSON/parse is not

Bravi15:03:50

hey everyone. how can I import goog stuff in my files?

Bravi15:03:00

spacemacs doesn’t seem to recognise that namespace at all

pesterhazy15:03:36

I don't know what the editor has to do with it

Bravi15:03:36

thanks, that’s what I was looking for. well spacemacs usually resolves the dependencies and it suggests the imports when u start typing at the top

eraserhd15:03:39

How would one do the equivalent of (extend-type java.util.Map ...) for clojurescript? I've just discovered that (extend-type cljs.core/IMap ...) does not work.

dnolen15:03:02

there’s no way to do that

dnolen15:03:18

the closest is to implement a default which checks for those protocols

pmooser16:03:45

So these days can we just use npm-deps for cljs instead of prepacked cljsjs projects? I'm trying but running into some errors, but it may be that I'm doing it wrong.

pmooser16:03:39

I'm trying naively, but getting: Uncaught Error: Undefined nameToPath for react_syntax_highlighter

pmooser16:03:55

(upon loading something in a browser which tries to do a require)

lwhorton17:03:45

can anyone point me to some alternative approaches to styling components in cljs? I know there’s garden and cljss and stylefy, but am I missing some other approaches?

pesterhazy17:03:52

simply using inline styles {:style ...} is an option

👍 4
hlolli17:03:10

[:style "target {rule: val}"] is sometimes handy, for pseudo selectors for example that are strange to type with clj keywords.

jmckitrick18:03:52

@pmooser Have you heard of the other approaches for this issue? ‘Double bundle’ and shadow-cljs?

pmooser18:03:38

@jmckitrick No, I will try to do a search and see what I can find. Thank you.

justinlee19:03:38

@pmooser This is my current thinking on how to do this. https://gist.github.com/jmlsf/f41b46c43a31224f46a41b361356f04d In particular, the :npm-deps feature is really experimental as of cljs 1.9 and doesn’t work in many situations, so I’ve explored other options.

pmooser20:03:56

@U8ES68TGX Thank you very much for the writeup. I'm not really a JS guy, so when this stuff breaks, I find it very difficult to even understand what is failing to work, etc. I will read the link you provided, and yeah, I'm having absolutely 0 luck with npm-deps so far for every project I've tried.

justinlee20:03:27

it’s going to be a lot easier to work with shadow-cljs

pmooser20:03:56

Yes, I'm a little worried about that, but it sounds like I just move to that for my main interface to compiling all of my cljs code and then it has the ability to work better with this stuff, if I understand correctly.

justinlee20:03:57

but yea, working with javascript libraries when you don’t know javascript is going have a learning curve 🙂

justinlee21:03:19

you should just think about it as a simpler, more friendly build tool

pmooser21:03:45

Well, it's funny, because it's not like the semantics or syntax of the underlying language is what is getting me - it's all ecosystem stuff, like how do you solve conflicting dependency versions or what do you do if there's some precompilation step required, etc ...

justinlee21:03:03

Yes that is the issue with js

pmooser21:03:11

Ok well thank you very much, I may shift gears to try to get my build (without this npm stuff) working with shadow-cljs, and then maybe revisit this issue once I have that working.

justinlee21:03:19

Of course, for me, coming in the reverse direction, it’s the same difficulty I have with cljs

pmooser21:03:44

Sure. The cljs folks seem allergic to providing any sort of out-of-the-box experience for anything though, which definitely makes it worse for everyone.

pmooser21:03:06

I've been using closure for about a decade now and the cljs stuff is just horribly unclear about even features they are supposed to support, like the bootstrapped repl for example.

pmooser21:03:07

Anyway, I love working in clj/cljs but this part is definitely the least fun. Thank you again for your insight!

richiardiandrea19:03:56

Does anyone have reccomendation for a bit of sugar around clojurescript profiling? Ideally a lib with a couple of macros in it

john19:03:41

So I've got the beginnings of a chrome extension that allows you to inject cljs repl client js file that will connect out to a locally running repl server

cljs 12
john19:03:09

So I can inject a repl env into any web page

lwhorton23:03:16

i see lots of libs that do something like src/clj and src/cljs for their file tree, but I’ve also read elsewhere that this isn’t necessary and makes .cljc harder. which is more idiomatic?

john23:03:16

I think what matters there is what directories are being watched by which compilers. Sometimes you may want to watch different directories differently

john23:03:03

Perhaps there's other factors...

john23:03:26

But unless you need to watch the directories separately, you can use a common directory. The clojurescript source directory on master is pretty intermingled with clj, cljs and cljc files

john23:03:46

If you've got a massive web app that shares a common code base but the front end and back end are fairly different, it's pretty common to separate them for large projects I think. But it's really just a convention I believe.

john23:03:51

If you're going to be sharing a lot of code between clj, cljs and cljc, yeah, there's definitely a lot of efficiency in using a shared directory structure.

🎉 4