Fork me on GitHub
#clojurescript
<
2023-07-25
>
Andrea Ambu17:07:54

I'm using re-frame, shadowcljs and chrome. I have source-maps working but the stacktraces are littered of (anonymous) core.cljs:NNN because of so many #(...) and (fn [...] ...) . If I turn them to (fn my-fn ...) then stack traces are more understandable and come as (app$core$some$context$my-fn) core.cljs:NNN but that looks quite verbose. Is there a way to make anonymous fns already put whatever the context is in the reported fn name for stack traces?

Kent Bull17:07:27

what did you have to do for sourcemaps to work?

p-himik17:07:12

With shadow-cljs, source maps work out of the box. Unless you have them disabled in your browser.

Andrea Ambu17:07:02

@U02SLLZ1STE I've bumped in all the guard-rail errors and it worked. Shadowjs emits .map files next to your .js files, ensure you can GET them from the browser you use to test your app and then they should work if your browser has them enabled.

2
Madara Uchiha18:07:02

A bit of a beginner question: I want to log values to the browser console, works fine with primitives but with objects what I get is a complex JavaScript representation of the ClojureScript value. I know that there's (pr-str) which gives me a string (but then I lose my ability to traverse nested structures etc) and I have (clj->js) (but then it's a JS object and not strictly the CLJS object I want). Is there a more idiomatic way to do this? I'm using figwheel-main if that makes a difference.

2
Madara Uchiha18:07:16

Well clearly that doesn't work for me.

thheller18:07:31

they are only available in chrome? other browsers unfortunately don't support them

Madara Uchiha18:07:31

Clearly not working for Firefox @ Ubuntu 😂

thheller18:07:28

no clue what the state of them is for firefox. there was a ticket for years, not sure if that went anywhere

thheller18:07:03

seems like its a thing?

Madara Uchiha18:07:32

I don't have that option in my devtools settings lol

p-himik18:07:17

Cljs-devtools are definitely worth using Chrome(ium) for development.

p-himik18:07:04

Just tested - they work in Firefox as well, but for whatever reason at the moment you have to enable them via flags and not via the config UI.

❤️ 6
Madara Uchiha19:07:27

Better than before

Madara Uchiha19:07:10

Interestingly it still gives off the warning

Madara Uchiha19:07:45

Ah, I was on 1.0.6 and apparently exactly this was fixed in 1.0.7, upgrading makes it look like chromium

Madara Uchiha19:07:53

Now to figure out dark theme 😂

Madara Uchiha18:07:44

Alright, on a totally different topic. I saw that you can use <p! to transform a promise (or a promise chain) into a go-block (and subsequently, a channel) - is there an easy way to do the opposite? (-> (magic some-chan) (.then #(do-thing %))

thheller12:07:12

(defn chan->p [chan]
  (js/Promise.
    (fn [resolve reject]
      (go (if-some [msg (<! chan)]
            (resolve msg)
            (reject nil))))))

thheller12:07:31

something like that should work, although I wouldn't recommend it since chans and promises are fundamentally different

Madara Uchiha13:07:51

Thank you! How do you do things like make fetch requests etc idiomatically? I can imagine a sort of async/await-esque using (go and (<p! but is that how "you do it"? What's the idiomatic way to do "async web development things"

thheller14:07:23

I don't use core.async at all in the frontend. only regular promises and callbacks

dnolen15:07:56

You don’t need a go block for this I think. You can just use take

2
thheller16:07:55

yikes, that is true 😛