This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-12
Channels
- # announcements (4)
- # babashka (93)
- # beginners (43)
- # calva (56)
- # cherry (4)
- # clerk (58)
- # clj-otel (4)
- # cljs-dev (1)
- # clojure (31)
- # clojure-conj (1)
- # clojure-dev (30)
- # clojure-europe (88)
- # clojure-india (2)
- # clojure-italy (3)
- # clojure-nl (1)
- # clojure-norway (17)
- # clojure-uk (2)
- # clojurescript (5)
- # clr (13)
- # conjure (2)
- # cursive (4)
- # data-science (4)
- # datalevin (1)
- # fulcro (3)
- # gratitude (7)
- # hyperfiddle (27)
- # kaocha (3)
- # lsp (9)
- # malli (6)
- # nbb (1)
- # off-topic (41)
- # pedestal (2)
- # practicalli (1)
- # rdf (3)
- # re-frame (3)
- # reitit (10)
- # releases (1)
- # shadow-cljs (8)
- # testing (3)
- # vim (2)
- # xtdb (7)
How would you imagine a test viewer which displays test failure? three columns (or rows) of expected, actual, diff?
been using the following fn on a project to sidestep sci when using clerk with a running cljs compiler, maybe others find it useful. cc @sritchie09
(defn cljs-render
"Takes a symbol pointing at a cljs render function and constructs a
viewer that looks up the `:render-fn` in the global `js`
environment, without going through sci if `cljs.compiler/munge` can
be resolved."
[sym & args]
(apply viewer/with-viewer
{:transform-fn viewer/mark-presented
:render-fn (if-let [cljs-munge (resolve 'cljs.compiler/munge)]
(symbol "js" (name (cljs-munge sym)))
sym)}
args))
I guess you could also have
:evaluator :javascript
and then just insert a javascript expression in there like:
globalThis.my_awesome.function
though I think I prefer the above as it will still use sci without the cljs compiler being available
https://github.com/mentat-collective/Clerk-Utils/blob/main/src/mentat/clerk_utils/show.cljc
Show-cljs was Mattās take on this idea
It will use SCI in both cases, but in one case it just evaluates the expression to the global function, and in the other case, something that's available in a SCI ns
Define code in a cljc file and autogenerate the js function that the viewer invokes, with some reload logic
@U04V15CAJ right, but itās not going through sci to look up the function I mean
@sritchie09 yep, though show-cljs
& friends are a bunch of macros and this is one function š
Yeah fair, if you donāt want to see the viewer code which often you donāt this is better
thatās fixed with https://github.com/nextjournal/clerk/compare/cljs-viewer?expand=1#diff-7ca6703fa7760530e47d2d6c66c67f6a9b140d40bc19737722aa84062c05a9daR797
here is the no-macro version:
(with-state {:point [1 1]}
(fn [!sym]
(mafs
(cartesian)
(circle
{:center [0 0]
:radius (q (mafs.vec/mag (:point @~!sym)))})
(movable-point
{:atom !sym
:path :point}))))
checking now
^::clerk/sync
(defonce server-state
(atom [1 1]))
(mafs/mafs
(mafs/cartesian)
(mafs/circle
{:center [0 0]
:radius `(abs @server-state)})
(mafs/movable-point
{:atom `server-state}))
vs this
(with-let [point [1 1]]
(mafs/mafs
(mafs/cartesian)
(mafs/circle
{:center [0 0]
:radius `(abs @~point)})
(mafs/movable-point
{:atom point})))
pretty similar! I had to provide the quoted symbol for the server-side one, and ditch the tilde inside the function I passed for radius
This is cool though:
`(abs @server-state)
this is using emmyās abs
via SCIserver-side rendering with clerkā¦ the form at the top dynamically builds a viewer. thoughts? there are some sneaky quotes in there
too magical?
okay here is the classic question for everyone. where should these functions live??
1. they could live in mafs.cljs and offer a clj + clerk interface. but they require an Emmy dependency to serialize functions across. That would feel nice because there is no clj
code now, so youād gain a clj
interface in the same project. But it would be very Clerk + Emmy-ish. Which is fine of course!
2. Or do the new dependencies imply that they go into emmy-viewers
? The downside here is that MOST of the mafs clj
-side is not Emmy-related.
in some sense it doesnāt matter. but Iāll follow the same route for leva, mathbox, mathlive, mafs, jsxgraph, so the pattern should feel appropriate.
If users only had to ever think about mafs.core
, mafs.coordinates
etc, instead of emmy.mafs.coordinates
... that is obviously better, since again Emmy is hiding behind the scenes here
@U07SQTAEM and for the eventual āopen in mariaā weāll want to make sure that this new API works on the cljs side too. so maybe that does imply a different library, since we want these functions to return reagent fragments
isnāt maria using https://github.com/mhuebert/yawn?
okay nice, so I need something new anyway
@sritchie09 The Maria -> Clerk pipeline is oneway.
For sure, for nowā¦ Iām anticipating the other direction down the road
I am actively hostile to that plan. The educational wiki thing of your heartās desire is not Maria, though they may share many ideas and components.
Interesting, can you say more?
The vision for Maria involves considerable simplicity. Itās meant to introduce people to programming at all, from which I would prefer they graduate via the Maria->Clerk project exporter. The thing that allows hosting complex notebooks with arbitrary deps, at least in the near term, will be Garden. The thing further down that road, multiplayer/wiki/&c, is the thing you want.
given that I can open gists in Maria it didnāt seem too far off to imagine opening a projectās file
@U07SQTAEM got it, that clarifies for sure
If you think about the deps situation for Clerk projects (basically anything Clojure call pull in), it becomes clear why Maria canāt run them all in the browser. I understand that Emmy can do it, but most other libraries canāt.
when mafs.cljs is consumed as a normal cljs lib, thereās no issue with passing functions, is there?
thatās right @U5H74UNSF. emmy helps there by allowing you to compile your fns to be fast, use automatic differentiation, etc, but everything works fine with cljs functions
@U5H74UNSF and in this srver-side model, if you didnāt have emmy you can] also pass a quoted function body like '(fn [x] (+ (Math/sin x) 10))
(mafs/mafs
(mafs/cartesian)
(mafs/of-x '(fn [x] (+ 2 (Math/sin x)))
{:color (:green mafs/Theme)}))
yeah itās useful for sure. I could definitely do emmy as an optional dependency, where if itās available the function compilation code comes online
like clerkās render part is potentially also useful as its own library but Iām happy I havenāt extracted it yet as things are still in flux
yeah, good call. note that this is possible and extract down the road