nextjournal

jlmr 2021-11-10T12:05:17.096900Z

Hi! Just started playing with Clerk, wonderful tool! One question though: is it possible to prevent a form from rendering? I have some deeply nested forms that Clerk tries to render completely and it slows down the browser to the point it is not usable anymore.

mkvlr 2021-11-10T14:15:20.098500Z

Hi, is that using the latest version of Clerk (0.3.220)? If not, please try an upgrade. If yes, I'd love to see the date, can you share it?

jlmr 2021-11-10T14:40:38.098700Z

Yes it’s the latest version. Basically it’s a any data produced by libraries like https://github.com/davidsantiago/hickory that parse HTML into edn. So it’s basically trees where each level does not have that many children, but the depth of the tree can be huge at places.

jlmr 2021-11-10T14:41:00.098900Z

I presume Clerk chokes on it because it looks at counts for collections

jlmr 2021-11-10T14:42:11.099100Z

(require '[hickory.core :as hick])

(-> ""
    slurp
    hick/parse
    hick/as-hickory)

👍 1
jlmr 2021-11-10T14:43:02.099300Z

^ this should produce a data structure to test with

mkvlr 2021-11-10T15:50:03.103600Z

@jlmr I can reproduce the issue, thank you!

👍 1
2021-11-10T15:19:08.102300Z

I'm trying out Clerk, it's really promising to me, I like it seems to be similar to a hot-reloading clojurescript project where you keep your namespaces fresh. I do have an issue:

(require '[ :as io]
         '[xtdb.api :as xt])

(defn start-xtdb! []
  (letfn [(kv-store [dir]
            {:kv-store {:xtdb/module 'xtdb.rocksdb/->kv-store
                        :db-dir (io/file dir)
                        :sync? true}})]
    (xt/start-node
     {:xtdb/tx-log (kv-store "data/dev/tx-log")
      :xtdb/document-store (kv-store "data/dev/doc-store")
      :xtdb/index-store (kv-store "data/dev/index-store")})))

(def node (let [_run-at #inst "2021-11-10T15:09:43.090-00:00"]
            (start-xtdb!)))
But start-xtdb! seems to be called again, which causes the notebook page to error because of lockfiles in the db. I expected the _run-at trick would work for this kind of issue.

mkvlr 2021-11-10T15:57:45.104300Z

great to hear you find it promising. So in general I’d advise against using the run-at / inst trick for stateful things you only want to happen once since they will not be called if clerk caches them across restarts

mkvlr 2021-11-10T15:58:22.104500Z

also Clerk has a threshold built in and doesn’t consider things that execute faster than that worth caching

mkvlr 2021-11-10T15:59:06.104700Z

can you use some other mechanism like an atom or another side-effectful check to make sure this happens only once?

mkvlr 2021-11-10T16:00:04.104900Z

I haven’t done much / any of stateful things like that so I’m eager to learn what the best approach here is 😼

borkdude 2021-11-10T16:03:54.105100Z

(defonce node ...)?

➕ 1
2021-11-10T16:31:33.105500Z

Ah, the threshold thing explains my surprise. I'm also doing a bunch of stateful mutations to the db in the namespace but it's not a big deal. Although perhaps meta for "cache this anyway" would be useful. Or as @borkdude said, in the cljs world I use defonce for this stuff!

2021-11-10T16:32:03.105700Z

(declare node)

(def node
  (if (bound? (var node))
    node
    (start-xtdb!)))
seems to do the trick without turning into an atom

borkdude 2021-11-10T16:39:29.105900Z

why not defonce ?

mkvlr 2021-11-10T16:39:58.106500Z

oh that sounds like another bug in Clerk

2021-11-10T17:01:07.106700Z

Oh, I haven't tried defonce, I thought that was a cljs only thing 😅

borkdude 2021-11-10T17:06:19.106900Z

it's not ;)

mkvlr 2021-11-10T19:12:58.110400Z

does that work? Though I think you should tag that with ^:nextjournal.clerk/no-cache then. Maybe something we should do automatically?

mkvlr 2021-11-10T19:13:33.110700Z

but not sure, maybe you do want a defonce to be cached…

borkdude 2021-11-10T19:14:02.110900Z

isn't that the idea of defonce ? execute only once, regardless of how many times you reload

mkvlr 2021-11-12T15:59:26.114400Z

did a defonce end up serving your needs here?

2021-11-10T15:20:34.102700Z

Is the letfn callback throwing this off maybe? Let me check.

2021-11-10T15:38:41.103400Z

that was not it 😞

respatialized 2021-11-10T18:19:15.108Z

Is it possible in Clerk to render a form's output without its source code (like how Nextjournal provides a "hide source" option)?

mkvlr 2021-11-10T18:22:48.108200Z

not yet

mkvlr 2021-11-10T18:22:57.108400Z

but certainly planned

mkvlr 2021-11-10T18:24:11.108600Z

main difficulty is the names of the options, think we might want to allow hiding the code and/or results with and without the ability to unhide them

2021-11-11T09:35:48.111200Z

I think there are 2 use cases: 1. hide all code 2. hide individual code forms How to realize this is indeed not simple

mkvlr 2021-11-10T18:43:04.109800Z

Another small Clerk release following yesterday’s table viewer release: Clojars: https://clojars.org/io.github.nextjournal/clerk/versions/0.3.233 Changelog: https://github.com/nextjournal/clerk/blob/93c19314e4e657075176667781d38c0c15fa29ef/CHANGELOG.md#03233-2021-11-10