Is there a simple way to include css/js scripts?
I attempted to cljs a while back, but it took a huge chunk of my time and yielded nothing; I'm hoping css/js is easier, besides injecting at runtime with eval-cljs
the current recommended way is using alter-var-root , see https://github.com/nextjournal/clerk/issues/323#issuecomment-1457823019
Thanks
Also, can an atom be synced without triggering clerk's recompute every time? I'm trying to stream data from the server and recompute takes 400ms total for 2 synced atoms
if you want to send data to the server without a recompute, you can use nextjournal.clerk.render/clerk-eval (takes a form that it will eval on the server)
I'm trying to stream data the other. from the server to the client
if you only change the sync atom on the server, there should be no extra recompute
are you on the latest clerk?
or is one sync atom changing the other?
Initially, I was changing 2 sync'ed atoms. but now, I disable recompute and trigger it at the end of the function. However, I'm wondering how I can do without recompute for this stream and just send data from server to client. recomputing takes between 200ms to sometimes 500ms.
if you change it to a normal atom (no sync), and call
(nextjournal.clerk.webserver/update-doc @nextjournal.clerk.webserver/!doc)does that work and is that any faster?
speeding up recompute! is on my list for sure
if it is a normal atom, how would I be able to access it in render-fn?
with a viewer or eval-cljs
probably requires all a bit too much ceremony to be nice to use
but pretty swamped with client work atm so don’t have a lot of time to spend on clerk
One more thing if you don't mind.. > with a viewer or eval-cljs I don't quite get how. I'm guessing I haven't fully figured out viewers yet. I tried:
(def foo (atom 0))
(clerk/with-viewer
{:transform-fn clerk/mark-presented
:render-fn
(template
(fn [v]
(reagent.core/with-let
[]
[:div "foo: " v])))}
@foo)
(comment
(swap! foo inc)
(nextjournal.clerk.webserver/update-doc! @nextjournal.clerk.webserver/!doc)
,)
after calling update-doc! , the viewer doesn't reflect the new value (understandable since the nb isn't recomputed). but the preview of (def foo ...) in the browser changes.
So I'm still unsure how that is happening. I've tried to access foo from within the viewer as well as with (clerk/eval-cljs '(prn foo)) and (clerk/eval-cljs (prn foo))` , but cljs doesn't find any such var(ns stream
(:require [nextjournal.clerk :as clerk]
[nextjournal.clerk.webserver :as webserver]))
(clerk/with-viewer {:render-fn '(fn []
(when-not (resolve 'user/my-atom)
(intern *ns*
'my-atom
(reagent.core/atom [])))
[nextjournal.clerk.render/inspect @@(resolve 'user/my-atom)])}
{})
(comment
(webserver/render-eval '(swap! user/my-atom conj (rand-int 10))))this works but it’s not pretty
btw with render-nrepl you can also get a nrepl into clerk’s render env
gave a demo in https://www.youtube.com/watch?v=07k0IFviazg
Yh it worked..
by any chanc, do you recall what viewer is used for top-level defs? I thought it was var-viewer, but that simply renders the var's name (`(def foo (atom 0)` is different from (do (def foo (atom 0)))). I'd like to inspect the viewer and see how it accesses the atom.
I'm still interested in this approach cause it handles diffs. Otherwise, I'd need my own set of macros to play nice with the render-eval method