hoplon

The :hoplon: ClojureScript Web Framework - http://hoplon.io/
2018-08-22T14:50:02.000100Z

For example the above library can add a la carte reactivity to a lightweight dom system like @onetom described above (or improved templating for hoplon proper?)

2018-08-22T14:50:18.000100Z

(defn reconciliate! [old-el new-el]
  (r/apply (r/diff new-el old-el) old-el))

(defn tpl [f]
  (fn [& args]
    (let [e (apply f (map deref args))]
      (doseq [arg args]
        (add-watch arg (gensym)
                   (fn [k ref o new]
                     (->> (map #(if (= % ref) new (deref %)) args)
                          (apply f)
                          (reconciliate! e)))))
      e)))

2018-08-22T14:50:41.000100Z

(`r/...` is an alias of reconcile.js)

2018-08-22T14:50:58.000100Z

(def x (atom 0))
(def y (atom 100))
(def z (atom []))

(defn page3 []
  (div
    ((tpl
      (fn [x* y*] (div
                  (str "x is" x*)
                  (str "y is" y*)
                  )))
     x y)

    ((tpl (fn [z*] (div ;;required non-empty div due to bug in reconcile.js
                     (div (for [n z*] (div (str n "!"))))))) 

     z)
    (button {:onclick #(swap! x inc)} "click")
    (button {:onclick #(swap! y + 100)} "click2")
    (button {:onclick #(swap! z conj (rand))} "click3")))

2018-08-22T14:53:04.000100Z

definitely can be polished i think, but this works and in my initial tests seems considerably more efficient than hoplon templating

onetom 2018-08-22T15:00:45.000100Z

@jjttjj thanks for the example, i will think about it! my only concern with code which is using (add-watch) is how is it going to be reloadable, to make sure that there are no obsolete change handler functions are fired.

2018-08-22T15:05:29.000100Z

good point, haven't considered that