Fork me on GitHub
#clojurescript
<
2022-08-19
>
Evan Z03:08:42

So now I’m using re-frame and reagent, and when I C-x C-e to update a function definition, I don’t see any update in the browser

Evan Z03:08:01

what’s the right way to make this work?

Evan Z03:08:08

I mean I don’t understand exactly how this should work — I think I have to call reagent-dom/render but I’m not sure how you call this ergonomically when working in emacs like this

tbtb14:08:20

This is probably a very newbie question, but is there an easy way to get the string representation of a javascript object representing a clojure hashmap? So if I have a hashmap like {:a "value"} it gives me "{a: "value"}" (this is for generating some javascript from clojure for something very hacky.

ersin14:08:21

in clojurescript you can use clj->js function as (clj->js {:a “value”})

dpsutton14:08:27

`❯ clj -A:cljs -M -m cljs.main -re node -r
ClojureScript 1.10.773
cljs.user=> (.stringify js/JSON (clj->js {:a 1}))
"{\"a\":1}"

👍 2
dpsutton14:08:17

The answer is “turn the cljs object into a js object and then serialize it”

tbtb14:08:11

Thank you

Ben Lieberman15:08:07

so I'm 98% sure using for here is totally wrong but also it halfway does what I want it do?

(defn ask-question? [q a]
  (if (= (js/prompt q)
	    a)
    true
    false))

(for [[q a] q-and-a]
  (try (ask-question? q a)
       (catch ExceptionInfo e
         (.log js/console e))))
But instead of letting me capture any output it throws clojure.lang.ExceptionInfo which I can't catch or log for some reason

dpsutton15:08:59

mixing js/console and clojure.lang.ExceptionInfo sounds very strange

p-himik15:08:04

How exactly do you run it? Seems to work just fine for me. Also, no need for an if if you return true or false - you can just return the condition.

p-himik15:08:38

Oh, also, yeah. clojure.lang.ExceptionInfo is a Clojure thing, not a ClojureScript thing. So that exception comes from your server, perhaps from the REPL process itself.

Ben Lieberman15:08:37

according to the stack trace map the :type is :js-eval-exception

Ben Lieberman16:08:04

I am using cider-eval-last-sexp

p-himik16:08:42

Does a plain (js/prompt "?") work like that? If yes, then whatever Cider does probably can't handle that expression in a for, just like David said outside the thread.

Ben Lieberman16:08:19

@U11BV7MTK @U2FRKM4TW I do get the prompts in the browser, which for whatever reason for causes, but when I tried doseq and some of the others like run it doesn't

Ben Lieberman16:08:36

but also I'm very hazy with the various functions that trigger operations on seqs

dnolen15:08:08

@bhlieberman93 for is not a loop it’s a list comprehension thing. You should not use this for side-effects, if you need a imperative loop use something else