Fork me on GitHub
#clojurescript
<
2021-02-09
>
dazld11:02:28

I'm sure this comes up all the time, but I couldn't find a simple explanation - by what process can I get output of prn/`pprint` etc in my repl, and not the browser console? I guess something has intercepted this..?

p-himik11:02:55

By default they should print out in your REPL. The redirection to the browser console is usually done explicitly by calling (enable-console-print!).

p-himik11:02:27

So either that function is called somewhere in your code or it's called by something in your setup. Or maybe the print function is set directly with set-print-fn!. In any case, the answer to your question depends on your setup and your code. Impossible to say anything without knowing about those two.

dazld11:02:41

thanks @U2FRKM4TW - assuming something is calling this, is there a way to get the current repl as a print target to override that call later?

p-himik11:02:15

There is, by calling set-print-fn! yourself. There's also set-print-err-fn!.

p-himik11:02:43

And you might also want to (set! *print-newline* true).

p-himik11:02:20

The value that you have to pass to those set-*-fn! functions depends on your particular REPL. The default CLJS browser REPL that you start with cljs.main uses clojure.browser.repl/repl-print.

๐Ÿ‘ 3
dazld11:02:19

having a play, thanks a ton!

๐Ÿ‘ 3
dazld11:02:26

I guess shadow has its own location for the repl - clojure.browser.repl/repl-print appears to be undefined

dazld11:02:35

i'll go check the docs.

p-himik11:02:20

Huh, shadow-cljs prints in both places for me.

dazld12:02:55

that would be ideal

dazld12:02:09

(prn :hi) from the repl, prints to the repl and the browser, this is great

dazld12:02:24

the same from within, say, a reagent component or function, only prints to the browser

dazld12:02:55

thanks - i'll go ask in the shadow channel.

thheller13:02:51

use (with-out-str (pprint foo)) to get the string

thheller13:02:07

oh nvm

๐Ÿ˜‰ 3
fsd20:02:09

Hello there, I am having little problem, So I have array of :tasks [{:unitid 1} {:unitid 2}] and so on, which is pulled from api and stored as state. How do I add more objects into this ? I tried doing the following but it just overrides it. I tried doing (swap! State* assoc :tasks {:test 1} ) Result is :tasks {:test 1} Can someone please tell me whatโ€™s going on? I would like my results to be :tasks [{:unitid 1} {:unitid 2} {:test 1} ]

dpsutton20:02:00

ignore the atom. assoc takes a map, a key, and a value and returns the map with that key value pair added to it. (assoc {:a :b} :a :new) will return {:a :new}. If you want to modify a map as you're intending you want to use update. In this case (update {:a [:b]} :a conj :new) will yield {:a [:b :new]}. Putting this together with the atom functions: (swap! State* update :tasks (fnil conj []) {:test 1}) should do what you want. I'm using fnil to handle if there's not already a value present with that key to use [] instead of nil

fsd21:02:10

Thank you so much it worked

parens 3