              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.

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

(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)
      app-view))

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

  {:inspect-data true
   :history      true})

; TODO: remove previous watches on hot reloads? they may leak memory by holding onto the old app instances

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

                         :on-start
                         (do
                           (app-control model signal dispatch-signal dispatch-action)

                           (-connect-atom r model dispatch-signal))

                         :on-stop
                         (do
                           (-unconnect-atom r model)

                           (app-control model signal dispatch-signal dispatch-action))

                         [::on-reset new-model]
                         (dispatch-action [::reset new-model])
