 
 
 ;; -----------------------------------------------------------------------------
-;; Simple Animation Cycle
+;; Render Cycle
 
-(defn animate [timestamp state]
+(defn render! [timestamp state]
   (let [app-name (get-in state [:app :name])
         env-time (get-in state [:env :time])
         fps (get-in state [:env :frames-per-second])

    (set! (.-innerText (app-div))
          (string/join ", " [app-name fps env-time timestamp mouse-pos]))))

(declare request-simple-animation)

(defn simple-animation-cycle [timestamp]
  (when (get-in @state [:app :simple-animation?])
    (request-simple-animation)
    (animate timestamp @state)))

(def request-simple-animation (partial poly/request-animation-frame
                                       simple-animation-cycle))

(defn setup-simple-animation! []
  (swap! state assoc-in [:app :simple-animation?] true)
  (request-simple-animation))

(defn teardown-simple-animation! []
  (swap! state assoc-in [:app :simple-animation?] false))


;; -----------------------------------------------------------------------------
;; Simple Render Cycle

(defn render []
  ;Update the dom
  true)

(defn request-frame [f]
  (poly/request-animation-frame f))

(declare step)

(def request-step (partial request-frame step))

(defn step [timestamp]
  (request-step)
  (render))

(defn simple-render-cycle [timestamp]
  (poly/request-animation-frame simple-render-cycle)
  (render))


;; -----------------------------------------------------------------------------

  (poly/set-title! (get-in @state [:app :name]))
  (setup-event-channels!)
  (setup-event-subscriptions!)
  (start-rendering!))

(defn teardown []
  (console/info "teardown")
  (stop-rendering!)
  (teardown-event-subscriptions!)
  (teardown-event-channels!))

