 
   (set! (.-onclick (.getElementById js/document "png")) #(open-as-png! (:canvas @app-state)))
 
-  (set! (.-onclick (.getElementById js/document "toggleStats")) toggle-stats!)
+  (set! (.-onclick (.getElementById js/document "toggleStats")) (fn [e] (toggle-stats! app-state e)))
 
 
   (re-render! app-state))

     :opacity 0.9
     :color "red")))

(defn handle-state-change!
  [_ app-state old-state new-state]

  (when-not (= (:rendering-data old-state)
               (:rendering-data new-state))

    (when-not (= (:rendering-data new-state) (last @rendering-data-history))
      (swap! rendering-data-history conj (:rendering-data new-state)))

    (re-render! app-state))

  (when-not (= (:stats old-state)
               (:stats new-state))

    (render-stats! app-state)))

(defn undo!
  "Revert app-state to the previous value"
  []

             (aget e "ctrlKey"))
    (open-as-png! (:canvas @app-state))))

(defn init!
  "Initialise event handlers, add atom watches, do the first rendering"
  []
