     (doseq [child-key to-remove]
       (js-delete child-states child-key))))
 
-(defn- replace-attrs! [node node-state old-attrs new-attrs]
-  (let [old-style (:style old-attrs)
+(defn- replace-attrs! [node node-state new-attrs]
+  (let [old-attrs (.-attrs node-state)
+        old-style (.-style node-state)
         new-style (:style new-attrs)]
     (dispose-attrs node-state)
-    (replace-attrs!* node node-state
-                     (dissoc old-attrs :style)
-                     (dissoc new-attrs :style)
-                     bind-attr!)
-    (replace-attrs!* node node-state
-                     old-style
-                     new-style
-                     bind-style-prop!)))
+    (set! (.-attrs node-state)
+          (replace-attrs!* node node-state
+                           old-attrs
+                           (dissoc new-attrs :style)
+                           bind-attr!))
+    (set! (.-style node-state)
+          (replace-attrs!* node node-state
+                           old-style
+                           new-style
+                           bind-style-prop!))))
 
 ;; From hiccup.compiler:
 (def ^{:doc "Regular expression that parses a CSS-style id and class from an element name."

      (let [k (name k)]
        (rebind-attr! node k v node-state)))))

(defn- replace-attrs!* [node node-state old-attrs new-attrs rebinder]
  (let [hit #js {}]
    (doseq [[attr-name new-val] new-attrs]
      ;(println "rebinding" attr-name new-val)
      (rebinder node attr-name new-val node-state)
      (when (get old-attrs attr-name)
          (aset hit (str attr-name) true)))
    (doseq [[attr-name _] old-attrs]
      (let [attr-str (str attr-name)]
        (when-not (aget hit attr-str)
          ;(println "unbinding" attr-name)
          (rebinder node attr-name nil node-state))))))

;(defn- replace-attrs!* [node node-state old-attrs new-attrs rebinder]
;  (loop [[[k new-val] & new-attrs] (seq new-attrs)


(declare get-transition)

(defn- init-element-meta! [state element-spec tag ]
  (let [m (meta element-spec)]
    (set! (.-meta state) m)
    (when-let [on-disposed (get m :node-disposed)]
      (set! (.-disposed-callback state) on-disposed)))
  (set! (.-tag state) tag))

(defn- reset-element-spec! [state spec tag]
  (when-let [on-disposed (.-disposed-callback state)]
    (on-disposed)
    (set! (.-disposed-callback state) nil))
  (set! (.-element-spec state) spec))

(defn- init-element-state! [dom-node element-spec tag]
  (let [node-id (str auto-node-id)
        state (ElementState. node-id false element-spec nil)]
    (set! auto-node-id (inc auto-node-id))
    (set-attr! dom-node "data-freactive-id" node-id)
    (init-element-meta! state element-spec tag)
    (aset element-state-lookup node-id state)
    (set! (.-freactive-state dom-node) state)
    state))
