hyperfiddle-2020
hyperfiddle-2020 copied to clipboard
hyperfiddle.ui/link API is obfuscated by reactivity
Userland renderers want this to be a simple for loop over the resultset:
- http://tank.hyperfiddle.net/:tutorial.blog/#:src
- http://tank.hyperfiddle.net/:clojurians/#:src
There is nothing editable on this view – you'd have to toggle to data mode, which is reactive out of the box – so the efficiency of the reaction is not something userland wants to think about.
The solution I want to explore is making the :hypercrud.browser/data key non-reactive, and the hyperfiddle.ui/table can lift the list-value into a reaction at the point of the unsequence.
One solution is formalizing the !list markdown directive as a first class ui api. Something like:
(defn hyperfiddle.ui/list [ctx f & [props]]
(->> (:hypercrud.browser/data ctx)
(r/unsequence (r/partial data/row-keyfn ctx))
(map (fn [[row k]]
^{:key k}
[f (context/row ctx row)]))
(doall)))
Then that blog renderer becomes:
[:dl
[hyperfiddle.ui/list ctx
(fn [ctx]
(contrib.reagent/fragment
[:dt [render-title @(:hypercrud.browser/data ctx)]]
[:dd (hyperfiddle.ui/link :hf/rel :view ctx (:hyperblog.post/title @(:hypercrud.browser/data ctx)))]))]]
I improved it in userland by pushing down the hack : (contrib.reactive/track identity row)
List is a solution, but the problem is it still obfuscates the map, so for example it becomes hard to sort it or change it to a mapcat
Another potential soln to link reactivity is to take a hard look at cats/Foldable and Traversable.
cats.core/foldm cats.core/traverse cats.core/filter cats.core/forseq cats.core/mapseq
Karl has explained to me that this is intractable due to the number of closures involved. I would like to understand again and write it down this time. Because going full cats could result in an acceptable enduser api.