Closed fdserr closed 6 years ago
This is an interesting one. I'm wondering what the behavior should be.
Here is a solution in the meantime:
(def render (fn [state node]
(set! (.-innerHTML node) (str "Click me count: " (:count @state)))
(set! (.-onclick node) #(swap! state update-in [:count] inc)))))
(defn render-on-change [render-fn]
(fn [state node]
(add-watch state :rendering (fn [_ _ _ _] (render-fn state node)) ;; idempotent
(render-fn state node)))
(defcard dom-node-updating
"Seems dom-node doesn't update?"
(dom-node (render-on-change render)
{:count 0}
{:inspect-data true})
The parens may be wrong, this is just a quick sketch.
Thanks much, that should do the trick for now.
I ran into this too and came up with a similar solution, but I also notice that the history controls don't appear when the state first changes. They show up after I save the file and Figwheel reloads or make a second state change.
good point, that makes sense
On Fri, Oct 23, 2015 at 7:28 AM, Eric Shull notifications@github.com wrote:
I ran into this too and came up with a similar solution, but I also notice that the history controls don't appear when the state changes. They only show up after I save the file and Figwheel reloads.
— Reply to this email directly or view it on GitHub https://github.com/bhauman/devcards/issues/48#issuecomment-150548123.
The following card shows the issue (include
dom-node
in the devcards:require-macros
and paste-in):I have tracked the problem down to
defonce-react-class DomComponent
here: https://github.com/bhauman/devcards/blob/d3a3000593e5b07827ebc98ffe152f1a6520b486/src/devcards/core.cljs#L314AFAIK it does not make use of the
:data_atom
passed to it bydefn- dom-node*
here: https://github.com/bhauman/devcards/blob/d3a3000593e5b07827ebc98ffe152f1a6520b486/src/devcards/core.cljs#L498I'm not react-able enough to fix this, sorry =[ (and therefore in great need of
dom-node
!)