   (atom
    {:app {:name "Spinning"
           :version "0.1.0"
+          :measure-fps? false
+          :simple-animation? false
           }
     :ech {:env-keyboard-key nil
           :env-mouse-click nil



;; -----------------------------------------------------------------------------
;; Init/Load

(defn ^:export on-init []
  (console/info "on-init")
  (lg :on-init "Start intializing.")
  (poly/set-title! (get-in @state [:app :name]))
  ; Create a canvas element inside the "app" div.
  (lg :on-init "End intializing.")
  ;(klang/show!)
  ;(inspect @state)
  (request-simple-animation)
  ;(request-step)
  )

(defn ^:export on-load []
  ; stop
  (console/info "on-load")
  (lg :on-load "The Dom is in the house!")
  ; re-start
  )

(defn get-event-listener-key [k]
  (get-in @state [:ech k :listener-key]))

(defn setup-event-channel! [k [listener-key channel]]
  (swap! state assoc-in [:ech k]
         {:channel channel :listener-key listener-key}))

(defn setup-event-channels! []
  (setup-event-channel! :env-keyboard-key (poly/listen-put! js/window :key))
  (setup-event-channel! :env-mouse-click (poly/listen-put! js/window :mouse-click))
  (setup-event-channel! :env-mouse-move (poly/listen-put! js/window :mouse-move)))

(defn teardown-event-channel! [k]
  (poly/unlisten! (get-event-listener-key k) (get-event-channel k))
  (swap! state assoc-in [:ech k] nil))

(defn teardown-event-channels! []
  (map teardown-event-channel! (keys (:ech @state))))


;; -----------------------------------------------------------------------------
;; Event Handlers

(defn on-env-frames-per-second [fps]
  (swap! state assoc-in [:env :frames-per-second] fps)
  (get-in @state [:app :measure-fps?]))

(defn on-env-keyboard-key [m]
  (console/info (:poly/keyword m))
  ;(inspect m)
  (condp = (:poly/keyword m)
    :a :>> #(klang/hide!)
    :q :>> #(klang/show!)
    nil))
