Fork me on GitHub

how do I use modulo (%) from cljs ?


mod or rem

👍 4

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


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


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


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


@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


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


@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.


You are definitely seeing a dynamic loading failure related to spec and test check. (This code is triggering

😮 4

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?


yes, request it.


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


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


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


@thheller: got it; thanks random aside: apparently is OKAY with trailing commas, whereas JSON/parse is not


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


spacemacs doesn’t seem to recognise that namespace at all


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


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


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.


there’s no way to do that


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


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.


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


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


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?


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

👍 4

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


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


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


@pmooser This is my current thinking on how to do this. 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.


@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.


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


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.


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


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


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 ...


Yes that is the issue with js


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.


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


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.


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.


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


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


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

So I can inject a repl env into any web page


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?


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


Perhaps there's other factors...


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


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.


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