Fork me on GitHub
#shadow-cljs
<
2018-06-29
>
haywood17:06:22

Can someone sorta explain how the cljs browser repl works with regards to eval'd values and re-compilation? It's kind of magic how I can declare an atom, and then reset! the value when the code path is executed by me in the browser and deref that value in the repl to mess around with it. Is there a way to persist that value in the repl so that it survives a re-compilation?

haywood18:06:14

oh I guess I could shove it into local-storage

haywood18:06:43

also is it possible to declare 'global' functions that are available at the repl no matter which namespace is currently selected?

haywood18:06:43

this is all inside the cljs-repl started via (shadow/nrepl-select :app)

justinlee18:06:56

you can make a value survive recompilation by using defonce instead of def. that’s what you’ll want to with your application state

justinlee18:06:22

i’m not sure what you mean by >then reset! the value when the code path is executed by me in the browser and deref that value in the repl to mess around with it.

haywood18:06:29

ah awesome

haywood18:06:14

doing stuff like that, where I want to mess around with a value so I'll reset it in an atom. 'exercise' the code in the browser, come back and the atom will have the value

haywood18:06:19

it's pretty magic, and awesome

haywood18:06:40

lines 3 and 5 are afterwards when I'm messing around

haywood18:06:22

oh man, defonce is a game changer thanks

justinlee18:06:33

maybe the piece you are missing is that when you drop into the cljs repl (by calling (shadow/nrepl-select :app) you are actually running code on the browser

justinlee18:06:05

whatever code your run in the cljs repl is just like running javascript in the browser console, except that it gets compiled to js first

haywood18:06:40

yea the fact that I can write arbitrary code, eval it in the repl, and it gets compiled on the fly down to javascript and eval'd in the correct place is pretty wild

haywood18:06:45

you're right

haywood18:06:52

is there a way to declare values in the repl that are "above" or global to all namespaces?

justinlee18:06:09

that’s why the cljs repl is often totally effed up and hard to get going. you have a menage a trois of the browser, your editor / tty, and cljs compiler (which is running in java)

justinlee18:06:34

i don’t think so. people often ask for it but i haven’t seen an answer

haywood18:06:53

yea it's been working great for me, especially paired with debux

haywood19:06:17

so I was able to import debux and declare a 'global' dbg atom in cljs.user. and I can refer to those globally by fully qualifying the namespace 🙂

haywood19:06:33

that basically satisfies my request for global stuff