hey! here is the test setup that I use for clojurescript: https://betweentwoparens.com/clojurescript-test-setup
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
RE: testing reagent I use a combination of react test tools and https://testing-library.com/docs/react-testing-library/intro/
RE: learning TDD/BDD Can you elaborate of what you are looking to learn?
@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
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.
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]]]])
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
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.
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.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.
@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
What is ui
?
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
.
is there pretty print alternative to println? I would like to be able to inspect clojure data in the browser console
found it in cljs.pprint 🙂
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
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
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".
ok ill look them up thanks!
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?
@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?
I really care
Ah, OK. I’ll investigate that route. Thanks!
It wouldn't surprise me if e.g. Chromium and FireFox require different approaches to achieve that.
What makes you think so @p-himik?
Because I've seen plenty of algorithms where different implementations perform differently (sometimes drastically so) in different browsers.
Good to know. Anyway, how would you handle it?
Right now, I do it via (-> js/JSON.parse js->clj) and the walking recursively over all the keys
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.
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.
I need all the data
I was hoping that there would be a lib out there that addresses this (common?) use case.
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?
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.
for speed
Ideally, these would really be shaded, but they're not
I see. Thanks!
We communicate between fronted and backend over JSON
The payload is big in some cases. That’s why we care about perfs
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.
20-30 if you add key caching.
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
What version of CLJS are you using?
I can reproduce it with 1.8.40 but cannot with 1.10.773.
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.
Looks like it was using org.clojure/clojurescript {:mvn/version "1.10.520"} before.
Hmm, must have been older than that... since this also works on 1.10.520.
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.
Ah, right.
Ah, thanks for finding the change!
NP
that's a 1.10 feature in clj (and cljs)
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.
cool, curious to see what you came up with
ah I see https://github.com/clojure/clojurescript-site/pull/369
@kommen Let me know if any of that doesn't seem right or I've left out anything important.
Yeah, I realized that I needed to back off to (symbol (name kw))
anyway for Clojure 1.9 compatibility (this is for HoneySQL v2).