hoplon

The :hoplon: ClojureScript Web Framework - http://hoplon.io/
2018-01-17T07:01:12.000207Z

@micha do you know what https://github.com/candera/vmt/blob/master/src/weathergen/cljs/macros.clj#L23 is about?

2018-01-17T07:07:26.000061Z

> Avoids some of the code-walking problems of the Hoplon macros.

2018-01-17T07:07:32.000034Z

which problems and what macros?

2018-01-17T07:07:40.000335Z

@candera ^^

2018-01-17T09:13:10.000247Z

@flyboarder i think you might have missed some places that when-dom is wrapping on! >.<

2018-01-17T09:31:56.000205Z

yay, this passes!

2018-01-17T09:32:00.000106Z

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

2018-01-17T09:33:27.000639Z

keyed-for-tpl seems awesome

2018-01-17T09:36:08.000110Z

could do with a slight refactor, but it does indeed seem to make DOM elements track the position of list items by keyfn

2018-01-17T10:07:56.000403Z

@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?