This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-21
Channels
- # babashka (11)
- # beginners (15)
- # cider (2)
- # cljdoc (36)
- # cljsrn (3)
- # clojure (6)
- # clojure-europe (9)
- # clojurescript (17)
- # conjure (3)
- # deps-new (6)
- # emacs (3)
- # fulcro (4)
- # gitpod (1)
- # gratitude (14)
- # introduce-yourself (2)
- # joker (14)
- # lsp (1)
- # luminus (7)
- # malli (6)
- # polylith (7)
- # releases (1)
- # reveal (3)
- # sql (4)
- # vim (18)
Hey, I saw some cool examples for things done with babashka http-server, For example: https://github.com/kloimhardt/babashka-scittle-guestbook I want to try working with it, but I'm not sure how to set up the workflow. It seems that to update changes in guestbook.clj I need to restart the server, and to reflect changes in guestbook.cljs I have to refresh the page. I tried to load the file into nrepl but then it starts a server and won't recieve new input. I'm probably missing some basic concept about how all of this work. So: Is there a way to refresh the page on file change? Is there a way to reload the server on file change? Is there a way to do actual hot reload? Thanks!
Hi @ozfraier
> I tried to load the file into nrepl but then it starts a server and won't recieve new input.
The reason is that the @(promise)
block the thread, so new evals are blocked.
One solution is to commenting the last part (server block) using the discard reader #_
https://clojure.org/guides/weird_characters#_discard before evaluate the file in the REPL and then
call core-http-server
to manually start the server (or evaluate the form (srv/run-server home-routes {:port port})
).
After that you can evaluate your modified blocks as usual.
(defn core-http-server []
(srv/run-server home-routes {:port port}))
#_ ; <-- Check the discard reader
(let [url (str ":" port "/")]
(core-http-server)
(println "serving" url)
(browse/browse-url url)
@(promise))
You're welcome @ozfraier.
Another solution (my preferred) is to use environment variable to exclude the server block when running the nrepl server dev=true bb --nrepl-server
, so in your code you can
put a condition against this env.
It's what I'm doing in this project: https://github.com/prestancedesign/babashka-htmx-todoapp/blob/master/htmx_todoapp.clj#L232-L237
This way, we avoid the risk to commit with the discard reader. 👍
@ozfraier @admin055 another way to do this is to use the babashka.file
property: https://book.babashka.org/#main_file
(when (= *file* (System/getProperty "babashka.file"))
(let [url (str ":" port "/")]
(core-http-server)
(println "serving" url)
(browse/browse-url url)
@(promise)))
Then you can eval the file without accidentally running the serverBrilliant! This is definitely the solution that I will use from now on. Thanks @U0510902N!
For my latest attempt at the Exercism test runner I ditched everything and went with a babashka script. It will run whenever code is submitted on the new site, and its job is to just take a solution file and a test file and output a detailed report.
I'm going about this very naively, but I ended up overriding the reporting methods in clojure.test
to store their results in atoms and process their contents accordingly.
The next case that I need to handle is what to do if either of the files contain invalid code. The error output is actually perfect, I just don't know the proper way of capturing this data while the script (or another?) is running so that it can be included in the report and displayed to the user.
The script is here: https://github.com/exercism/clojure-test-runner/blob/845341d84494c3d8b087dffa1a7fba44ca086be5/test-runner.clj
Any help or feedback would be appreciated, thanks!
The error reporting stuff isn't exposed at this point but I want to do this in the near future
Maybe I could pick it apart first with rewrite-clj and only test the valid forms.