This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-22
Channels
- # announcements (3)
- # beginners (22)
- # braveandtrue (6)
- # calva (2)
- # cider (85)
- # cljdoc (1)
- # cljs-dev (21)
- # cljsrn (2)
- # clojure (70)
- # clojure-italy (9)
- # clojure-spec (1)
- # clojure-uk (144)
- # clojure-ukraine (6)
- # clojurescript (109)
- # cursive (59)
- # data-science (15)
- # datomic (40)
- # emacs (8)
- # fulcro (64)
- # funcool (8)
- # graphql (8)
- # hispano (3)
- # hoplon (7)
- # jobs-discuss (29)
- # leiningen (3)
- # luminus (2)
- # off-topic (13)
- # onyx (9)
- # parinfer (49)
- # pedestal (2)
- # portkey (8)
- # re-frame (10)
- # reagent (33)
- # reitit (13)
- # ring (2)
- # ring-swagger (16)
- # shadow-cljs (193)
- # spacemacs (1)
- # sql (19)
- # tools-deps (19)
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?)
(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)))
(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")))
definitely can be polished i think, but this works and in my initial tests seems considerably more efficient than hoplon templating