Fork me on GitHub
#clerk
<
2023-06-23
>
mkvlr10:06:44

heads up, made some simplifications of Clerk’s https://github.com/nextjournal/clerk/commit/70af0c7f6cf19bc69c816960c430e6c9e43ea530. I hope they’re really internals but always hard to know 😆. Would love it if folks could take it for a spin and let me know if a more gradual migration is warranted. cc @sritchie09 maybe some of your code could be affected by this change?

2
Sam Ritchie01:06:03

I don’t think this will hit anything I’ve got but I’ll give it a close look

zachcp16:06:24

this would be amazing if hooked up to the Observable's https://observablehq.com/@observablehq/duckdb client.

apbleonard15:06:57

By varying clerk-demo's notebooks/controls.clj I have 2 sliders for atoms, x and y, which when manipulated update the referenced @x and @y values that are displayed - lovely. However in my domain y can't be less than x. I'd hoped to make the y slider move higher when the x slider was manipulated to go past its current value with the following - but it didn't work. Any suggestions? 🙂

(when (< y x)
  (reset! y @x)
  (clerk/show! 'my-ns))

mkvlr15:06:35

try this:

;; # Controls! 🎛
^{:nextjournal.clerk/visibility {:code :hide}}
(ns controls
  {:nextjournal.clerk/no-cache true}
  (:require [nextjournal.clerk :as clerk]
            [nextjournal.clerk.experimental :as cx]))


^{::clerk/sync true ::clerk/viewer cx/slider}
(defonce x (atom 0))

^{::clerk/sync true ::clerk/viewer cx/slider}
(defonce y (atom 0))

^::clerk/no-cache
(when (< @y @x)
  ;; NOTE: there's currently an optimization in Clerk to not send
  ;; messages backe to the sender. We can opt out of this with this
  ;; binding to get the slider to move
  (binding [nextjournal.clerk.webserver/*sender-ch* nil]
    (reset! y @x)))

❤️ 2
apbleonard15:06:24

Yep - worked! Absolutely awesome 😊 I have a "simple" workplace formula taking £a -> £b with 6 configuration parameters whose calculation is implemented in Clojure/Java, and just complicated enough to be hard to picture safely in my head. Within a day I now have a plot of the function dynamically changing in response to the 6 config sliders, using the same function code as we use in production. I've worked here 7 years and never quite got my head around it properly. Now I can use this to help my team understand it better too. Thank you very much!

🖤 2
mkvlr16:06:43

ah that’s great to hear, thanks for sharing!

apbleonard11:06:39

Is there a way to clear out the state/caching on the browser? When I adjust the sliders it's hard to get them back to where the code puts them on first load (the typical config settings for us). Tried refresh, clearing browser cache, using incognito window etc. Happy even to kill the atom using browser dev tools and then refresh but I'm not sure where to find it :)

mkvlr19:06:43

you’d like to restore the original state of your atoms? (reset! your-atom init-val) but not sure I’m fully understanding your question.

apbleonard19:06:33

Hah I guess that would work of course. I was thinking to have a way of doing it from the browser side but there's no need for that really. This page can't be statically published so devs would be running it and can reset as you say. I'll add the required resets to the comment block with the other commands needed to run up the page. Thanks again :)

mkvlr19:06:10

sure thing. Since the atom contents are synced you can do it on either side and the result should be the same.