hyperfiddle-2020
hyperfiddle-2020 copied to clipboard
Widgets migrate to (f e a rets adds)
Here is what the picker interface could look like
(defmethod hf/render #{:rosie.hyperfiddle.sub/locations :swing/display-sub} [ctx props]
#?(:cljs
[picklist
(assoc ctx
; This way is too much programming, not declarative enough
::hf/view-change! (fn [ctx] ; no longer needed
(fn [os ns] ; [e a rets adds]
(let [rets (set/difference os ns)
adds (set/difference ns os)]
(runtime/with-tx ctx ; lift up and parameterize
(location-picker-tx (hf/e ctx) :sub/tags rets adds)))))
; Better way
::hf/with-tx! runtime/with-tx
::hf/view-change! (fn [e a rets adds]
(location-picker-tx e :sub/tags rets adds)))
(merge props
{:html/id `sub-locations-picker
::hf/needle-key :needle
:options :swing/all-locations})]))
Note the route-change interfaces need to be thought through. Does (hf/swap-route! ctx assoc needle-key n) make sense with [e a rets adds]?
Acceptance criteria
- pickers work like this
- good strategy for routestate pickers
- other widgets are migrated (string, date, etc)
https://github.com/hyperfiddle/hyperfiddle/commit/8aafcc5882a7215d957177ad633fdb80f4fce72a
(defmethod hf/render #{:rosie.hyperfiddle.sub/locations :swing/display-sub} [ctx props]
#?(:cljs
[picklist
(assoc ctx
; Better way
::hf/target ::hf/route ; <--- dispatch to multimethod, default would be stage
::hf/view-change! (fn [e a rets adds] ; This could be (have) a default value
(location-picker-tx e :sub/tags rets adds)))
(merge props
{:html/id `sub-locations-picker
::hf/needle-key :needle
::hf/options :swing/all-locations})]))
Luke says: Let's slow down, unsure if this is the right thing.
Luke says: Don't know where the old value comes from, is this from debounce? Not all controls use debounce