Fork me on GitHub
#clojurescript
<
2021-02-02
>
Atiq Gauri03:02:03

@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

thheller07:02:22

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.

DoubleU10:02:16

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.

p-himik11:02:39

What is ui?

p-himik11:02:45

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.

DoubleU15:02:15

Thanks for the responses @U2FRKM4TW, 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.

👍 3
kommen10:02:17

@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

cap10morgan14:02:32

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

Fredrik Andersson11:02:48

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

Fredrik Andersson11:02:37

found it in cljs.pprint 🙂

souenzzo11:02:50

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-himik11:02:43

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

Fredrik Andersson13:02:37

ok ill look them up thanks!

p-himik12:02:37

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

Yehonathan Sharvit13:02:43

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?

p-himik14:02:09

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

Yehonathan Sharvit14:02:26

What makes you think so @U2FRKM4TW?

p-himik14:02:59

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

Yehonathan Sharvit15:02:15

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

Yehonathan Sharvit15:02:53

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

p-himik16:02:18

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-himik16:02:02

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 Sharvit16:02:16

I need all the data

Yehonathan Sharvit16:02:42

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

p-himik17:02:29

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?

Yehonathan Sharvit18:02:34

We communicate between fronted and backend over JSON

Yehonathan Sharvit18:02:04

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

p-himik18:02:54

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-himik18:02:40

20-30 if you add key caching.

Yehonathan Sharvit07:02:02

You mean a function that parses a JSON string or a function that parses the result of JSON.parse?

p-himik07:02:21

The latter.

p-himik07:02:53

I wouldn't implement my own JSON.parse - it's highly optimized in browsers, you just can't get on that level of performance from the JS level.

martinklepsch08:02:11

@U0L91U7A8 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?

p-himik17:02:07

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.

Alex Miller (Clojure team)17:02:00

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

p-himik17:02:21

I see. Thanks!

seancorfield20:02:28

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-himik20:02:41

What version of CLJS are you using?

p-himik20:02:17

I can reproduce it with 1.8.40 but cannot with 1.10.773.

seancorfield20:02:21

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.

👍 3
seancorfield20:02:28

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

seancorfield20:02:00

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

p-himik20:02:01

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-himik20:02:08

Ah, right.

seancorfield20:02:24

Ah, thanks for finding the change!

Alex Miller (Clojure team)20:02:43

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

seancorfield20:02:14

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

cap10morgan20:02:20

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.

kommen12:02:42

cool, curious to see what you came up with

cap10morgan15:02:14

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