Hey, Hi, Merry Christmas! I'm trying to develop a clerk viewer that could control individual values in the state map. For starters, I went after reproducing an integer slider just like the one that has been published in https://github.com/nextjournal/clerk/blob/main/src/nextjournal/clerk/experimental.clj#L26-L34. I made it work but stumbled on the problem that when I try to apply it to another value of the map or just evaluate it in any another way than as viewer annotation to the definition it blows up with an error informing about an attempt to dereference a nil. More details in the thread 🧵.
Let's assume that slider-for-key used below is actually experimental/slider with modified custom :render-fn. Then this works:
^{::clerk/sync true ::clerk/viewer (partial slider-for-key {:key :value1 :min 0 :max 20})}
(defonce !state (atom {:value1 10 :value2 50 :value3 75}))but if I try to view it again with different options (key) it throws an error No protocol method IDeref.-deref defined for type null: :
^{::clerk/sync true ::clerk/viewer (partial slider-for-key {:key :value2 :min 0 :max 1000})}
!state
or to be truthful even with the same value, but just in any different way than as along the definition:
^{::clerk/sync true ::clerk/viewer (partial slider-for-key {:key :value1 :min 0 :max 1000})}
!state
(slider-for-key {:key :value1 :min 0 :max 1000} !state)
(clerk/with-viewer (partial slider-for-key {:key :value1 :min 0 :max 1000}) !state)
I found out the exact same error occurs when I try to render nextjournal.clerk.experimental/slider in any other way too.
For example, this works:
^{::clerk/sync true ::clerk/viewer (partial cx/slider {:min 0 :max 1})}
(defonce bar (atom 0))
showin the slider as expected, but below usages result in the same error as the one mentioned above
;; below usages of the same viewer don't:
^{::clerk/viewer (partial cx/slider {:min 0 :max 10})}
bar
(cx/slider {:min 0 :max 1000} bar)
(clerk/with-viewer (partial cx/slider {:min 0 :max 10000 :step 100}) bar) That prompted me to not seek the bug in my custom slider's :render-fn, coz those two viewers' render functions are different and the error is the same. That leaves https://github.com/nextjournal/clerk/blob/main/src/nextjournal/clerk/viewer.cljc#L1306-L1324 to be the common denominator and most probably the source of problem.
Above are observations and here's what I'm thinking now:
• disabling :var-from-def? makes the error go away (just like viewer results/sliders in the notebook page 😅)
• :transform-fn is has a cond check (var-from-def? x) (*recur* (*->* x :nextjournal.clerk/var-from-def symbol))
I would appreciate any help in solving this case. Either by resources/examples helping me develop my version of render-eval-viewer or by pointing me to some other parts of clerk, that could help me achieve the goal.
FTR screenshot of the errors while using slider-for-key: