hyperfiddle-2020 icon indicating copy to clipboard operation
hyperfiddle-2020 copied to clipboard

hyperfiddle.ui/link API is obfuscated by reactivity

Open dustingetz opened this issue 7 years ago • 5 comments

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.

dustingetz avatar Oct 05 '18 14:10 dustingetz

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.

dustingetz avatar Oct 05 '18 14:10 dustingetz

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)))]))]]

khardenstine avatar Oct 05 '18 16:10 khardenstine

I improved it in userland by pushing down the hack : (contrib.reactive/track identity row)

dustingetz avatar Oct 05 '18 16:10 dustingetz

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

dustingetz avatar Oct 05 '18 16:10 dustingetz

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.

dustingetz avatar Nov 23 '18 14:11 dustingetz