|
13 | 13 |
|
14 | 14 | (def slider
|
15 | 15 | {: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}))) |
19 | 19 | :render-fn '(fn [{:keys [var-name value]}]
|
20 | 20 | (v/html [:input {:type :range
|
21 | 21 | :initial-value value
|
|
43 | 43 | ;; (that is, the form Clerk is evaluating defines a var).
|
44 | 44 | {:pred ::clerk/var-from-def
|
45 | 45 |
|
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 |
| - |
53 | 46 | ;; When we specify a `:transform-fn`, it gets run on the JVM side
|
54 | 47 | ;; to pre-process our value before sending it to the front-end. In
|
55 | 48 | ;; this case we want to send the symbol for the var along with the
|
56 | 49 | ;; unwrapped value because our custom renderer will need to know
|
57 | 50 | ;; 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}))) |
60 | 60 |
|
61 | 61 | ;; The `:render-fn` is the heart of any viewer. It will be executed
|
62 | 62 | ;; by a ClojureScript runtime in the browser, so — unlike these
|
|
0 commit comments