Clojurians
#hoplon
<
2016-04-09
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

dm309:04:53

I've implemented a POC with MutationObserver-based attr change listeners: https://github.com/dm3/hoplon/commit/399c13953fb0446e9c3ba3c5ff45232e52d0a092

dm309:04:22

this doesn't remove observers, need to think when this makes sense

dm309:04:49

used like this:

(page "index.html"
  (:require [hoplon.attrs :as a]))

(defelem width-section [_ kids]
  (let [[w h] [(cell 100) (cell 100)]]
    (div :css (cell= {:border "1px solid black", :width w, :height h})
         :change/style #(println "Old:" (a/old-value %) ", new:" (a/new-value %))
         (button :click #(swap! w + 10) "inc width")
         (button :click #(swap! w - 10) "dec width"))))

(html
  (body
    (div :id "container"
         :css {:width "500px", :height "500px"}
         (width-section))))

dm309:04:45

a/old-value returns a string with the previous serialized attribute value, a/new-value returns an object with the current attribute value. In this case it's a CSSStyleDeclaration