              r
              (fn [_key _ref _old-state new-state]
                (when (not= @r new-state)
-                 (reset! r new-state)))))
+                 (reset! r new-state))))
+
+  #_(println "2 DATA ATOM WATCHES = " (pr-str (count (.-watches r)))))
+
+(defn -unconnect-atom
+  [r model]
+  (remove-watch r model)
+  (remove-watch model r))
 
 (defn add-atom-sync
   "Carry middleware.

  ; sync from reference for the first time
  (dispatch-signal [::on-reset @r])

  ; sync model from reference
  (add-watch r
             model

                         :else
                         (app-reconcile model action)))))))

(defn with-unmount-callback
  [_body unmount-cb]
  (r/create-class {:reagent-render         (fn [body _unmount-cb]
                                             (into [:div] body))
                   :component-will-unmount (fn [_this] (unmount-cb))}))

(defcard-rg
  counter-with-history
  (fn [data-atom _]
    (let [app (carry/app (-> counter/spec
                             (add-atom-sync data-atom)))    ; <-- connect devcards atom
          [_ app-view] (carry-reagent/connect app counter/view-model counter/view)]
      ((:dispatch-signal app) :on-start)                    ; <-- start the app

      [with-unmount-callback
       [app-view]
       #((:dispatch-signal app) :on-stop)]))                ; <-- stop the app on umount

  (atom (:initial-model counter/spec))                      ; <-- create devcards atom with initial model value

  {:inspect-data true
   :history      true})

;;;;;;;;;;;;;;;;;;;;;;;; Figwheel stuff
(defn before-jsload
