clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
benny 2020-12-05T13:01:46.146800Z

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

thheller 2020-12-05T13:02:42.147600Z

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

benny 2020-12-05T13:10:17.148500Z

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

william 2020-12-05T13:20:48.149500Z

noob question: this resets my-atom:

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

thheller 2020-12-05T13:21:34.149600Z

well I don't know enough about your runtime environment

thheller 2020-12-05T13:21:51.149800Z

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

william 2020-12-05T13:25:48.150100Z

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

benny 2020-12-05T13:26:29.150300Z

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

benny 2020-12-05T13:27:33.150500Z

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

thheller 2020-12-05T13:29:04.150700Z

that would not work with shadow-cljs

thheller 2020-12-05T13:29:27.150900Z

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

thheller 2020-12-05T13:29:33.151100Z

so you can totally have that running on your machine

thheller 2020-12-05T13:29:42.151300Z

while copying the output to the other thing

thheller 2020-12-05T13:29:52.151500Z

I'd typically recommend using something like sshfs though

thheller 2020-12-05T13:29:57.151700Z

avoid copying all the things all the time

thheller 2020-12-05T13:30:28.151900Z

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

thheller 2020-12-05T13:30:51.152100Z

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

benny 2020-12-05T13:31:04.152300Z

okay I think I get the gist

benny 2020-12-05T13:31:49.152500Z

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

thheller 2020-12-05T13:32:01.152700Z

exactly

benny 2020-12-05T13:32:16.152900Z

I will give it a try, thanks

thheller 2020-12-05T13:32:27.153100Z

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

thheller 2020-12-05T13:32:46.153300Z

defaults to use localhost which won't work

benny 2020-12-05T13:40:56.153500Z

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

benny 2020-12-05T13:41:02.153700Z

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

thheller 2020-12-05T13:42:41.153900Z

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

thheller 2020-12-05T13:43:38.154100Z

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

benny 2020-12-05T13:45:09.154300Z

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

thheller 2020-12-05T13:46:30.154600Z

npm install ws

thheller 2020-12-05T13:47:19.154800Z

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

thheller 2020-12-05T13:47:33.155Z

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

benny 2020-12-05T13:49:17.155200Z

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

benny 2020-12-05T13:49:32.155400Z

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

benny 2020-12-05T13:51:11.155600Z

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

thheller 2020-12-05T13:51:50.155800Z

probably configured :devtools-url in the wrong place

thheller 2020-12-05T13:51:59.156Z

should be in :devtools

thheller 2020-12-05T13:52:16.156200Z

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

thheller 2020-12-05T13:53:04.156400Z

don't forget the port too so :devtools {:devtools-url "<http://your-ip:9630>"} in your build config of course

benny 2020-12-05T13:57:06.156800Z

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

👍 1
GGfpc 2020-12-05T16:23:09.158Z

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 E 2020-12-05T17:53:54.158500Z

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-himik 2020-12-05T18:55:24.158900Z

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.

kiranshila 2020-12-05T20:54:29.160800Z

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.

thheller 2020-12-05T20:55:48.161Z

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.

kiranshila 2020-12-05T20:57:38.161600Z

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

rutledgepaulv 2020-12-05T21:00:18.162600Z

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.

rutledgepaulv 2020-12-05T21:01:19.162800Z

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

kiranshila 2020-12-05T21:01:32.163Z

My atom is top level though

rutledgepaulv 2020-12-05T21:01:47.163200Z

ok

kiranshila 2020-12-05T21:01:57.163400Z

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

kiranshila 2020-12-05T21:02:12.163600Z

I'm trying to make a MWE

rutledgepaulv 2020-12-05T21:02:39.164100Z

what is MWE ?

kiranshila 2020-12-05T21:02:53.164300Z

minimal working example

rutledgepaulv 2020-12-05T21:03:05.164500Z

:thumbsup:

kiranshila 2020-12-05T21:12:08.164900Z

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

kiranshila 2020-12-05T21:12:17.165100Z

All good! Thank you for your help @rutledgepaulv

rutledgepaulv 2020-12-05T21:12:34.165300Z

np. glad it was something silly