@micha do you know what https://github.com/candera/vmt/blob/master/src/weathergen/cljs/macros.clj#L23 is about?
> Avoids some of the code-walking problems of the Hoplon macros.
which problems and what macros?
@candera ^^
@flyboarder i think you might have missed some places that when-dom
is wrapping on!
>.<
yay, this passes!
(defn expandable
[item]
(let [expand? (j/cell false)]
(h/div
:data-expanded expand?
:click #(swap! expand? not)
(j/cell= (name item)))))
(deftest ??for-tpl--not-sortable
(let [items (j/cell [:a :b :c])
el (h/div (h/for-tpl [i items] (expandable i)))
first-child (first (hoplon.test-util/find el "div"))]
(is (not (.querySelector el "[data-expanded]")))
(hoplon.test-util/trigger! first-child "click")
(is (= "a" (hoplon.test-util/text first-child)))
(is (hoplon.test-util/matches first-child "[data-expanded]"))
; c should be expanded (it is positional in for-tpl)
; first-child should still reference the first child (nothing moves)
; the item text should be in reverse order (it is re-derived in expandable)
; event handlers should not break
(swap! items reverse)
(is (= "c" (hoplon.test-util/text first-child)))
(is (hoplon.test-util/matches first-child "[data-expanded]"))
(hoplon.test-util/trigger! first-child "click")
(is (not (hoplon.test-util/matches first-child "[data-expanded]")))))
(deftest ??keyed-for-tpl--sortable
(let [items (j/cell [:a :b :c])
el (h/div (h/keyed-for-tpl identity [i items] (expandable i)))
first-child (first (hoplon.test-util/find el "div"))]
(is (not (.querySelector el "[data-expanded]")))
(hoplon.test-util/trigger! first-child "click")
(is (= "a" (hoplon.test-util/text first-child)))
(is (hoplon.test-util/matches first-child "[data-expanded]"))
; a should be expanded
; first-child should be a reference to the last child now (because it moved)
; the items should be in reverse order
; event handlers should not break
(swap! items reverse)
(is (= ["c" "b" "a"] (map hoplon.test-util/text (hoplon.test-util/find el "div"))))
(is (= "a" (hoplon.test-util/text first-child)))
(is (hoplon.test-util/matches first-child "[data-expanded]"))
(hoplon.test-util/trigger! first-child "click")
(is (not (hoplon.test-util/matches first-child "[data-expanded]")))))
keyed-for-tpl
seems awesome
could do with a slight refactor, but it does indeed seem to make DOM elements track the position of list items by keyfn
@flyboarder reckon we could get a WIP from https://github.com/hoplon/hoplon/pull/231/files into a snapshot so that i could play around with it in context of an app?