                  (dissoc :mousedown-event)
                  (update-in [:rendering-data] zoom-to-enclose-rectangle! canvas x0 y0 x1 y1))))))
 
+(defn handle-state-change!
+  [_ _ old-state new-state]
+
+  (when-not (= (:rendering-data old-state)
+               (:rendering-data new-state))
+
+    (println (:rendering-data new-state) (last @rendering-data-history))
+    (when-not (= (:rendering-data new-state) (last @rendering-data-history))
+      (swap! rendering-data-history conj (:rendering-data new-state)))
+
+    (re-render! new-state)))
+
+(defn undo!
+  "Revert app-state to the previous value"
+  []
+  (println @rendering-data-history)
+  (when (> (count @rendering-data-history) 1)
+    (swap! rendering-data-history pop)
+    (swap! app-state assoc :rendering-data (last @rendering-data-history))))
+
 (defn add-overlay-handlers!
   "Adds handlers for zooming to the overlay canvas"
   [overlay-canvas]

  []
  (set! (.-onresize js/window) (fn [] (re-render! @app-state)))

  (add-watch app-state :state-changed
             (fn [_ _ old-state new-state]
               (when-not (= (:rendering-data old-state)
                            (:rendering-data new-state))
                 (re-render! new-state))))

  (add-overlay-handlers! (get @app-state :overlay-canvas))

  (render-mandelbrot! @app-state))


  variables for this kind of thing - I got it to be only ~10 times slower using the >> and << macros)"
  [{:keys [canvas overlay-canvas escape-radius]
    {:keys [scale x0 y0] :as render-state} :rendering-data}]

  (set-canvas-dimensions! canvas)
  (set-canvas-dimensions! overlay-canvas)
