clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
athomasoriginal 2021-02-02T01:06:13.304300Z

hey! here is the test setup that I use for clojurescript: https://betweentwoparens.com/clojurescript-test-setup

athomasoriginal 2021-02-02T01:06:37.304600Z

You will notice that it’s a lean setup and this is on purpose. I try to avoid too many tools and wrappers in general and lean on the JS ecosystem

athomasoriginal 2021-02-02T01:07:29.304800Z

RE: testing reagent I use a combination of react test tools and https://testing-library.com/docs/react-testing-library/intro/

athomasoriginal 2021-02-02T01:08:13.305100Z

RE: learning TDD/BDD Can you elaborate of what you are looking to learn?

Atiq Gauri 2021-02-02T03:38:03.309500Z

@thheller I have created source map for this template starter project: https://github.com/ahonn/shadow-electron-starter config:

{:main {:target :node-script
                 :main app.main.core/main
                 :compiler-options {
                                   :source-map true
                                   :source-map-include-sources-content true
                                   :source-map-detail-level :all}
                 :output-to "x/main.js"}
shadow-cljs version: 2.11.15 generate file main.js main.js.map works fine with your clojure function written here: https://clojureverse.org/t/server-side-decoding-of-javascript-sourcemaps/1591/3?u=thheller here are those sourcemap: https://github.com/rockg688/test Sentry has this open source sourcemap validator: https://sourcemaps.io/ (I need sourcemap to work with http://sentry.io) I get this strange error 1. while uploaded main.js 2. while uploaded main.js.map

Ricardo Cabral 2021-02-02T07:47:03.310100Z

Hi @tkjone thanks for replying to me. I have a looked in the link which you have sent. I am able to run lein test and also write normal test cases like: (deftest sample-test (is (= true true))). What I want to achieve is something like: I have a “home-page” component, a “menu” component and a “login”component. So there is a if inside my function if the user is logged in render the menu, otherwise a login page will be rendered.

Ricardo Cabral 2021-02-02T07:50:16.310300Z

Something as simple as : (defn home-layout [] (if-let [user (session/get :identity)] [home-user-layout] [home-login-layout] ) ) My components are simple as (defn home-login-layout [] [:div [h/render-header] [:div.columns [:div.column [l/login-component]]]])

Ricardo Cabral 2021-02-02T07:52:19.310600Z

I am trying to learn by writing the test first and for instance: when the user is not logged in it should render the login page. I will check the links you have shared. thank you

thheller 2021-02-02T07:54:22.310900Z

sorry I cannot debug sentry for you. it most likely is the problem with the source-map npm lib that everything JS based uses. you already linked the problem issue.

Ricardo Cabral 2021-02-02T08:21:16.311100Z

I believe this will help mehttps://francisvitullo.medium.com/a-way-of-testing-views-in-clojurescript-apps-98aaf57c5c2a however I have just realized that I need to read about re-frame

DoubleU 2021-02-02T10:08:16.316200Z

Hi all, was hoping i could get a hand with something. I’m using reagent and I’m trying to add a class to the the form-group div if there is an input value available. something like this:

[ui/form-group {:label          "Email"
                :id             "login-email"
                :name           "email"
                :type           "email"
                :class          "(.-value ? 'some-class-here' : '')".    <------How to do this 
                :required       true
                ...
But not quite sure how this logic works. I’ve tried using something like [(when .-value? "some-class-here")] but that doesn’t seem to work either. Any help would be much appreciated.

DoubleU 2021-02-03T15:42:15.402800Z

Thanks for the responses @p-himik, turns out someone else on the team had a different suggestion and we ended up going with that. I appreciate you taking the time to respond. Have a great day.

1👍
kommen 2021-02-02T10:32:17.322100Z

@cap10morgan Didn’t try :target :bundle yet for webworkers, but I think it should work to build webworkers with it, if you have the :bundle-cmd doing the right thing. so no probably no need for :target :webworker in that case

p-himik 2021-02-02T11:10:39.322200Z

What is ui?

p-himik 2021-02-02T11:11:45.322400Z

In general, you store the class or the value in some reagent.core/atom with some :on-change handler and use that value to determine what you pass to :class.

Fredrik Andersson 2021-02-02T11:29:48.323200Z

is there pretty print alternative to println? I would like to be able to inspect clojure data in the browser console

Fredrik Andersson 2021-02-02T11:33:37.323500Z

found it in cljs.pprint 🙂

souenzzo 2021-02-02T11:35:50.323900Z

I do [:pre (with-out-str (pp/pprint x))] But there is tap>, if you are using #shadow-cljs , you can see the result's pprinted and clicable at localhost:9630 There is the cljs-devtools, that when you enable custom formatters on chrome, you can do (js/console.log x) and it will show on console pprinted

p-himik 2021-02-02T11:47:43.324100Z

If it's only for the browser console, then you should absolutely check out https://github.com/binaryage/cljs-devtools and https://github.com/binaryage/dirac

p-himik 2021-02-02T12:45:37.326200Z

Just had a very unpleasant manifestation of the Mandela effect - apparently, ^ in NPM versions means "with the same left-most non-zero digit" (not even "same major", which is confusing by itself) whereas I was adamant that it meant "the exact same version".

Fredrik Andersson 2021-02-02T13:10:37.327100Z

ok ill look them up thanks!

Yehonathan Sharvit 2021-02-02T13:10:43.327300Z

What is the fastest way (in terms of CPU time) to parse a JSON string into a CLJS map where the keys are keywordized and transfomed to kebab case?

martinklepsch 2021-02-03T08:38:11.353Z

@viebel do you really care that it’s ClojureScript data structures or might it be enough to get something that behaves somewhat similarly like https://github.com/mfikes/cljs-bean?

Yehonathan Sharvit 2021-02-03T08:55:46.354900Z

I really care

cap10morgan 2021-02-02T14:38:32.328400Z

Ah, OK. I’ll investigate that route. Thanks!

p-himik 2021-02-02T14:42:09.328600Z

It wouldn't surprise me if e.g. Chromium and FireFox require different approaches to achieve that.

Yehonathan Sharvit 2021-02-02T14:50:26.328900Z

What makes you think so @p-himik?

p-himik 2021-02-02T14:55:59.329100Z

Because I've seen plenty of algorithms where different implementations perform differently (sometimes drastically so) in different browsers.

Yehonathan Sharvit 2021-02-02T15:56:15.329500Z

Good to know. Anyway, how would you handle it?

Yehonathan Sharvit 2021-02-02T15:56:53.329700Z

Right now, I do it via (-> js/JSON.parse js->clj) and the walking recursively over all the keys

p-himik 2021-02-02T16:02:18.329900Z

js->clj is probably the slowest thing. If you need just a subset of keys, you can simply use aget with goog.object or https://github.com/mfikes/cljs-bean or some other interop library. If you need all the data, you can write your own version of js->clj that focuses on the values that can be in JSON and converts all the keys in the process, without any intermediate steps.

p-himik 2021-02-02T16:03:02.330200Z

If you really care about performance, you should employ the scientific method to come up with the best result. And don't forget to test across all the platforms that will end up running that code.

Yehonathan Sharvit 2021-02-02T16:28:16.330400Z

I need all the data

Yehonathan Sharvit 2021-02-02T16:28:42.330600Z

I was hoping that there would be a lib out there that addresses this (common?) use case.

p-himik 2021-02-02T17:15:29.330800Z

Not that common, I think. As far as I can tell from passive observations, the following cases are much more common: - Not caring about the performance - Avoiding JSON altogether (transit is a great choice) - Not converting anything - just using JS objects via interop Can you share your particular use-case that has that need that you described?

p-himik 2021-02-02T17:23:07.331700Z

Why does ClojureScript jar include an AOT'ed version of clojure.data.json, clojure.tools.reader, and cognitect.transit? At least, 1.10.773 one.

alexmiller 2021-02-02T17:31:23.332Z

for speed

alexmiller 2021-02-02T17:32:00.332300Z

Ideally, these would really be shaded, but they're not

p-himik 2021-02-02T17:33:21.332400Z

I see. Thanks!

Yehonathan Sharvit 2021-02-02T18:42:34.333100Z

We communicate between fronted and backend over JSON

Yehonathan Sharvit 2021-02-02T18:43:04.333300Z

The payload is big in some cases. That’s why we care about perfs

p-himik 2021-02-02T18:50:54.333500Z

And that's why we have transit. :) I understand though that sometimes JSON is more preferable. But, as I mentioned, I don't think such use-case is that frequent. In any case, an obvious solution to your problem is a function that's about 10-15 lines long.

p-himik 2021-02-02T18:53:40.333700Z

20-30 if you add key caching.

seancorfield 2021-02-02T20:04:28.335200Z

Is this a known/intentional difference between clj and cljs:

(println (keyword 'sym)) ; clj and cljs both print :sym
(println (symbol :kw)) ; clj prints kw (as a symbol) but cljs throws an exception

;; cljs throws
var idx = name.indexOf("/");
               ^

TypeError: name.indexOf is not a function

p-himik 2021-02-02T20:06:41.335300Z

What version of CLJS are you using?

p-himik 2021-02-02T20:07:17.335500Z

I can reproduce it with 1.8.40 but cannot with 1.10.773.

seancorfield 2021-02-02T20:07:21.335700Z

Not a recent enough one, apparently! I updated my test runner from 3.7.0 to 3.8.0 which pulled in a more recent cljs version and now it works.

1👍
seancorfield 2021-02-02T20:08:28.336Z

Looks like it was using org.clojure/clojurescript {:mvn/version "1.10.520"} before.

seancorfield 2021-02-02T20:10:00.336200Z

Hmm, must have been older than that... since this also works on 1.10.520.

p-himik 2021-02-02T20:10:01.336400Z

Should've worked even with that one, given that "CLJS-2958 - make symbol work on keywords and vars" was ostensibly shipped with 1.10.516. But it's probably not that important, given that you got it working now.

p-himik 2021-02-02T20:10:08.336600Z

Ah, right.

seancorfield 2021-02-02T20:10:24.336800Z

Ah, thanks for finding the change!

p-himik 2021-02-02T20:10:46.337Z

NP

alexmiller 2021-02-02T20:25:43.337200Z

that's a 1.10 feature in clj (and cljs)

cap10morgan 2021-02-02T20:33:20.338300Z

Thanks for the :target :bundle webworker pointers, @dnolen and @kommen. I got it working! Going to submit a http://clojurescript.org PR in case it's helpful for others.

kommen 2021-02-03T12:02:42.369300Z

cool, curious to see what you came up with

kommen 2021-02-03T12:16:21.370600Z

ah I see https://github.com/clojure/clojurescript-site/pull/369

cap10morgan 2021-02-03T15:30:14.402600Z

@kommen Let me know if any of that doesn't seem right or I've left out anything important.

seancorfield 2021-02-02T20:48:14.338400Z

Yeah, I realized that I needed to back off to (symbol (name kw)) anyway for Clojure 1.9 compatibility (this is for HoneySQL v2).