This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-05
Channels
- # announcements (2)
- # babashka (19)
- # beginners (14)
- # biff (10)
- # calva (23)
- # clojure (49)
- # clojure-europe (15)
- # clojure-nl (3)
- # clojure-norway (25)
- # clojure-seattle (1)
- # clojure-uk (4)
- # clojurescript (7)
- # data-science (6)
- # datahike (3)
- # datomic (1)
- # emacs (13)
- # events (2)
- # fulcro (3)
- # graalvm (13)
- # hyperfiddle (32)
- # leiningen (4)
- # lsp (38)
- # malli (1)
- # missionary (34)
- # nbb (28)
- # off-topic (42)
- # other-languages (5)
- # portal (8)
- # practicalli (1)
- # re-frame (3)
- # releases (1)
- # ring (7)
- # shadow-cljs (13)
- # sql (3)
New to Clojure. I wrote a little countdown alarm script based on the ink-demo
, but when I tested it with 1000 hours, I encountered a JavaScript heap out of memory
error. I found out that the code below was causing significant memory and runtime overhead.
(doseq [n (range 1 @left-time)]
(js/setTimeout #(swap! left-time dec) (* n 1000)))
Therefore, I modified it to use setInterval instead.
(def count
(js/setInterval
#(if (> @left-time 0)
(swap! left-time dec)
(js/clearInterval count))
1000))
Should I submit a pull request in README
for this?@U03FJ0E8S8L please do!
Working on a web framework for personal projects big and small. One big enhancement would be to auto-refresh the browser after sending data to the nrepl server. Are there any systems in place that would at least let me observe the eval request? Thinking if I could at least react to eval, I could broadcast a SSE to the browser to refresh in development mode.
I see. I'll start by reading through https://github.com/babashka/nbb/blob/main/src/nbb/impl/nrepl_server.cljs and see where that leads
I guess you could re-define your eval keybindings to something which evaluates + also adds a (broadcast ..)
call to the mix in your editor
Oh right, something like that crossed my mind too. It's a viable alternative for personal use, but that would be a strong choice with the goal of publishing a framework
A quick solution I suppose would be to use something like browser-sync to watch cljs files, and refresh browser on save
On second thought, maybe auto-refreshing on eval is not a great DX. It's not uncommon to check state like:
(comment
@routes)
Which might create problems if it refreshes on every eval. Analyzing the eval to guess when it's a good idea to reload sounds messy so perhaps browser-sync or something more minimal inspired by it is a better solutionYeah that might work better: • Watch cljs files for changes • On save, connect to repl and eval the file, if successful send SSE to refresh • Server adds a script on dev mode to listen for those SSEs and triggers a refresh
Argh maybe not, (sorry thinking out loud), not every file save should be eval'd. So maybe proxy request, but try and distinguish between a form eval (don't refresh), and a buffer or file eval (refresh). I am pretty sure every time I eval'd a buffer or file, I immediately refreshed the page to look for changes.
For the middleware approach, is it critical it matches the existing nrepl middleware interface\implementation? In theory, it wouldn't be much work to create a promise-based ring-like middleware system for the nbb implementation
I already have the promise-based ring-like middleware for my request layer so copying that over would be fairly trivial.
I don't think nbb nrepl should be compatible with existing middleware since that's usually all based on JVM anyway, right
Awesome! This is what middleware usage looks like https://github.com/jaidetree/gracieanimator/blob/c2dbacaffd21cd4fb9a2323a2e70c3a0d1b50f7b/src/gracie/server.cljs#L14-L26 and most are implemented here https://github.com/jaidetree/gracieanimator/blob/c2dbacaffd21cd4fb9a2323a2e70c3a0d1b50f7b/src/framework/middleware.cljs
To get started thinking... 1. Clone latest nbb (or update my fork) 2. Add in middleware args and support it in the server API 3. Use npm link 4. Link this client project to it, start with some logging middleware to see what happens Does that make sense? One more question that comes to mind: Should we support middleware out of nbb.edn or is it ok to start without that for now?
@U8WFYMFRU you might find this a useful reference too: https://github.com/chr15m/sitefox/blob/32d33aa723de9afa578efc4f35bcc8e2ddfbb7ae/src/sitefox/reloader.cljs#L10
It is not tested very well but last time I checked it was working.