Fork me on GitHub
#clojurescript
<
2020-12-05
>
benny13:12:46

I have an embedded environment (arm v7l) and want to get a cljs repl using only node. Anyone an idea how to get there? using shadow-cljs I can compile cljs to js and run it on the target platform, but the target platform has no java

thheller13:12:42

@b you can just run shadow-cljs on your machine. all you need is a websocket connection from node back to your machine

benny13:12:17

@thheller I wouldn't even know where to start with that, do you have a pointer?

thheller13:12:34

well I don't know enough about your runtime environment

thheller13:12:51

do you copy the code there manually? is it some sort of mounted disk? sshfs or so?

benny13:12:29

I copy the code manually via scp and run it via ssh "node script.js"

benny13:12:33

in my mind I would have to deploy a nrepl-server cljs bundle, which I can then invoke via "node nrepl.js" and that way I can connect to it from my dev environment

thheller13:12:04

that would not work with shadow-cljs

thheller13:12:27

the output of the shadow-cljs build is designed to connect back to the running shadow-cljs watch

thheller13:12:33

so you can totally have that running on your machine

thheller13:12:42

while copying the output to the other thing

thheller13:12:52

I'd typically recommend using something like sshfs though

thheller13:12:57

avoid copying all the things all the time

thheller13:12:28

you just might need to tune a couple settings since the :node-script output usually assumes that is running on the machine it was compiled on

thheller13:12:51

I don't actually know if this will work at all but in theory it can

benny13:12:04

okay I think I get the gist

benny13:12:49

sshfs to the target platform, so my "out"-dir is on the target platform and then I invoke shadow-cljs with watch and tune some parameters so my dev environment IP is used to connect back from node when I run node on the target platform

benny13:12:16

I will give it a try, thanks

thheller13:12:27

probably want to set :devtools-url, see the docs

thheller13:12:46

defaults to use localhost which won't work

benny13:12:56

I had this problem before, if I don't use release then I get an error when trying to run the script.js on the target

benny13:12:02

Error: ENOENT: no such file or directory, open '/home/root/.shadow-cljs/builds/script/dev/out/cljs-runtime/goog.debug.error.js'

thheller13:12:41

you need to configure :output-dir as well as :output-to

thheller13:12:38

otherwise it defaults to using the .shadow-cljs temp dir which you probably haven't mounted

benny13:12:09

now I get a new error when running "node script.js" on the target platform: Error: Cannot find module 'ws'

thheller13:12:30

npm install ws

thheller13:12:19

I assume here you have :output-dir "out" or so and that dir is mounted

thheller13:12:33

you can cd out; npm init -y; npm install ws on your machine

benny13:12:17

okay now there is no error, now we're at the part where it tries to connect to localhost

benny13:12:32

(I've set :devtools-url to http://my-internal/ip

benny13:12:11

okay I manually edited the global.CLOSURE_DEFINES property of shadow.cljs.devtools.client.env.server_host and it connects! Very cool

thheller13:12:50

probably configured :devtools-url in the wrong place

thheller13:12:59

should be in :devtools

thheller13:12:16

manually editing will override it on every compiled which will get annoying

thheller13:12:04

don't forget the port too so :devtools {:devtools-url ""} in your build config of course

benny13:12:06

yeah it works! this is incredible! 🙂 thanks a lot

👍 3
Carlo13:12:48

noob question: this resets my-atom:

(reset! my-atom 300)
but this doesn't:
(#(reset! my-atom %) 2)
do you know why?

Carlo13:12:48

ok it seems it was something in my keybindings that was evaluating the wrong thing. Never mind 😄

GGfpc16:12:09

Hello! Two questions: 1 - Can I use cljsjs packages along with npm packages in the same project? 2 - If I use npm packages do I have to import react if I'm using reagent?

D E17:12:54

2 - no, react comes bundled with reagent - but you can exclude it and add your own, see :exclusions here https://github.com/reagent-project/reagent

p-himik18:12:24

The answer to 2 depends on the build tool. With shadow-cljs, you don't have to exclude anything - you just need to install React via NPM.

thheller20:12:48

it is a bad idea to use cljsjs AND npm at the same time. you'll very likely have things duplicated and possibly conflicting with each other.

kiranshila20:12:29

Interesting reagent atom behavior that I am stuck on. I'm a few callbacks deep in a callback stack, and am trying to reset an atom to the argument passed into the callback. A call to reset! does nothing, while I am still unable to print the value. I wrote a little test function

(defn reset-and-print [atom val]
  (print val)
  (reset! atom val))
My value gets printed, but the atom does not get reset, and there are no errors.

rutledgepaulv21:12:18

probably the atom is being reset but you didn't close over it and so its recreating the component with a fresh atom each time and so it appears like nothing is changing.

rutledgepaulv21:12:19

(defn my-component-with-state []
	(let [showing (r/atom false)]
	  (fn [] 
	   	(if @showing 
	   	  [:div "Showing"]
	   	  [:button {:on-click #(reset! showing true)} "Not showing"]))))

kiranshila21:12:32

My atom is top level though

kiranshila21:12:57

I added a watch to it, and it is not getting updated

kiranshila21:12:12

I'm trying to make a MWE

kiranshila21:12:53

minimal working example

kiranshila21:12:08

Apparently my repl wasn't connected to the right browser session.

kiranshila21:12:17

All good! Thank you for your help @U5RCSJ6BB

rutledgepaulv21:12:34

np. glad it was something silly

kiranshila20:12:38

I tried with a normal atom, not an r/atom and I see the same behavior