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
@b you can just run shadow-cljs on your machine. all you need is a websocket connection from node back to your machine
@thheller I wouldn't even know where to start with that, do you have a pointer?
noob question: this resets my-atom
:
(reset! my-atom 300)
but this doesn't:
(#(reset! my-atom %) 2)
do you know why?well I don't know enough about your runtime environment
do you copy the code there manually? is it some sort of mounted disk? sshfs or so?
ok it seems it was something in my keybindings that was evaluating the wrong thing. Never mind 😄
I copy the code manually via scp and run it via ssh "node script.js"
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
that would not work with shadow-cljs
the output of the shadow-cljs build is designed to connect back to the running shadow-cljs watch
so you can totally have that running on your machine
while copying the output to the other thing
I'd typically recommend using something like sshfs though
avoid copying all the things all the time
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
I don't actually know if this will work at all but in theory it can
okay I think I get the gist
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
exactly
I will give it a try, thanks
probably want to set :devtools-url
, see the docs
defaults to use localhost which won't work
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
Error: ENOENT: no such file or directory, open '/home/root/.shadow-cljs/builds/script/dev/out/cljs-runtime/goog.debug.error.js'
you need to configure :output-dir
as well as :output-to
otherwise it defaults to using the .shadow-cljs
temp dir which you probably haven't mounted
now I get a new error when running "node script.js" on the target platform: Error: Cannot find module 'ws'
npm install ws
I assume here you have :output-dir "out"
or so and that dir is mounted
you can cd out; npm init -y; npm install ws
on your machine
okay now there is no error, now we're at the part where it tries to connect to localhost
(I've set :devtools-url to http://my-internal/ip
okay I manually edited the global.CLOSURE_DEFINES property of shadow.cljs.devtools.client.env.server_host and it connects! Very cool
probably configured :devtools-url
in the wrong place
should be in :devtools
manually editing will override it on every compiled which will get annoying
don't forget the port too so :devtools {:devtools-url "<http://your-ip:9630>"}
in your build config of course
yeah it works! this is incredible! 🙂 thanks a lot
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?
1 - yes, https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules
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
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.
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.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.
I tried with a normal atom, not an r/atom and I see the same behavior
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.
(defn my-component-with-state []
(let [showing (r/atom false)]
(fn []
(if @showing
[:div "Showing"]
[:button {:on-click #(reset! showing true)} "Not showing"]))))
My atom is top level though
ok
I added a watch to it, and it is not getting updated
I'm trying to make a MWE
what is MWE ?
minimal working example
:thumbsup:
Apparently my repl wasn't connected to the right browser session.
All good! Thank you for your help @rutledgepaulv
np. glad it was something silly