Skip to content

Commit 7664444

Browse files
committed
Update controls to new viewer api
1 parent 68c3cae commit 7664444

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

notebooks/controls.clj

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
(def slider
1515
{:pred ::clerk/var-from-def
16-
:fetch-fn (fn [_ x] x)
17-
:transform-fn (fn [{::clerk/keys [var-from-def]}]
18-
{:var-name (symbol var-from-def) :value @@var-from-def})
16+
:transform-fn (comp clerk/mark-presented
17+
(clerk/update-val (fn [{::clerk/keys [var-from-def]}]
18+
{:var-name (symbol var-from-def) :value @@var-from-def})))
1919
:render-fn '(fn [{:keys [var-name value]}]
2020
(v/html [:input {:type :range
2121
:initial-value value
@@ -43,20 +43,20 @@
4343
;; (that is, the form Clerk is evaluating defines a var).
4444
{:pred ::clerk/var-from-def
4545

46-
;; Normally, Clerk's front-end is very careful to fetch data from
47-
;; the JVM is bite-sized chunks to avoid killing the browser. But
48-
;; sometimes we need to override that mechanism, which is done by
49-
;; specifying an alternative `:fetch-fn`. In this case, we use a
50-
;; tiny function that says "just give me the whole value!"
51-
:fetch-fn (fn [_ x] x)
52-
5346
;; When we specify a `:transform-fn`, it gets run on the JVM side
5447
;; to pre-process our value before sending it to the front-end. In
5548
;; this case we want to send the symbol for the var along with the
5649
;; unwrapped value because our custom renderer will need to know
5750
;; both of those things (see below).
58-
:transform-fn (fn [{::clerk/keys [var-from-def]}]
59-
{:var-name (symbol var-from-def) :value @@var-from-def})
51+
;;
52+
;; Normally, Clerk's front-end is very careful to fetch data from
53+
;; the JVM is bite-sized chunks to avoid killing the browser. But
54+
;; sometimes we need to override that mechanism, which is done by
55+
;; calling `clerk/mark-presented` to ask Clerk to send the whole
56+
;; value as-is to the browser.
57+
:transform-fn (comp clerk/mark-presented
58+
(clerk/update-val (fn [{::clerk/keys [var-from-def]}]
59+
{:var-name (symbol var-from-def) :value @@var-from-def})))
6060

6161
;; The `:render-fn` is the heart of any viewer. It will be executed
6262
;; by a ClojureScript runtime in the browser, so — unlike these

0 commit comments

Comments
 (0)