This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-06
Channels
- # aleph (15)
- # announcements (2)
- # babashka (121)
- # beginners (62)
- # biff (6)
- # cherry (2)
- # cider (51)
- # clerk (30)
- # cljs-dev (5)
- # clojure (77)
- # clojure-austin (2)
- # clojure-europe (10)
- # clojure-germany (6)
- # clojure-nl (1)
- # clojure-norway (19)
- # clojure-romania (1)
- # clojure-uk (3)
- # clojurescript (16)
- # core-typed (7)
- # cursive (17)
- # datomic (12)
- # deps-new (11)
- # emacs (7)
- # events (2)
- # fulcro (5)
- # honeysql (2)
- # hyperfiddle (32)
- # introduce-yourself (1)
- # jobs-discuss (2)
- # membrane (18)
- # missionary (2)
- # music (5)
- # polylith (7)
- # reagent (26)
- # releases (5)
- # testing (32)
- # tools-build (14)
- # tools-deps (7)
- # xtdb (8)
How do I use the ::clerk/viewers
key in (clerk/table {::clerk/viewers ???} {…})
? I’m trying to use a custom number formatter within the table. I’ve tried putting a modified viewer/table-viewer
, a seq of it, a seq of viewer/table-viewers
, only my modified viewer/number-viewer
, and I can’t get anything to render. Most errors mention it can’t find a viewer with key ::viewer/table-viewer
including if it’s the only item in there. I wasn’t able to find any examples within the Clerk demos.
hi @U05CLS4TF6Z both these example work with the latest clerk
(clerk/with-viewers
(clerk/add-viewers [{:pred number? :render-fn '(fn [_ _] [:em "num"])}])
(clerk/table [[1] [2]]))
(clerk/table
{::clerk/viewers (clerk/add-viewers [{:pred number? :render-fn '(fn [_ _] [:em "num"])}])}
[[1] [2]])
thank you!
the point is with-viewers
(and the associated ::clerk/viewers option) actually do specify all the available viewers, so clerk/dd-viewers
prepends your custom ones to the list of the defaults
So interestingly, this doesn’t work when I want the number formatter to be used within the table. Attaching a snippet
The number viewer must first be attached to a table viewer
that’s very odd, there should be no need to add the number viewer to the inner table viewers
in fact this works again:
(def n-viewer
(dissoc (assoc viewer/number-viewer :render-fn '(fn [_ _] [:em "num"]))
:name))
(clerk/table
{::clerk/viewers (clerk/add-viewers [n-viewer])}
[[1] [2]])
Yep, dissoc
ing the name allowed it to work
that must be something related to how add-viewers work in wrt named viewers, but I don’t recall why we did this: https://github.com/nextjournal/clerk/blob/fc6df7186bfea2571fff2dd790d0ad63f8d6295f/src/nextjournal/clerk/viewer.cljc#L666-L670 cc @U5H74UNSF?
Either way, it’s an amazing tool and I want to thank yall for creating it!
add-viewers!
now does in-place positional replacement to make it easier to override them
there’s also a first-class :add-viewers
attribute on the table-viewer, also makes customization easier
see the Improve viewer customization
section in https://github.com/nextjournal/clerk/blob/main/CHANGELOG.md#015957-2023-09-28
I saw that originally, but wasn’t sure which was the preferred/recommended way to do
> Anonymous viewers (without a :name
) or new named viewers will be prepended to the viewer stack
I see, but having to dissoc the name of an existing viewer to have it take precedence sounds a bit odd
(ns scratch
(:require [nextjournal.clerk.viewer :as viewer]
[nextjournal.clerk :as clerk]))
(def my-number-viewer
(assoc viewer/number-viewer :render-fn '(fn [_ _] [:em "num"])))
(clerk/add-viewers! [(update viewer/table-viewer :add-viewers clerk/add-viewers [my-number-viewer])])
(clerk/table [[1] [2]])
but use :add-viewers
instead of :nextjournal/viewers
because the former takes precendence
Thanks!
Yep, makes sense. The add-viewers!
changes the default viewers correct?
or rather, if you used :nextjournal/viewers
but left the :add-viewers
on the table-viewer as-is, the table viewer would still use its original number viewer, so you woudln’t see the change
@U9EQP1K0X let’s go over this and document it next week