             [wordsmith.persistence :as p]
             [cljs.core.async :refer [put! chan <!]]
             [goog.events :as events])
-  (:import [goog.events EventType]))
+  (:import [goog.events EventType]
+           [goog.async Throttle]))
 
 (enable-console-print!)
 

    :change (change-document app params)
    :new    (new-document app)))

(defn listen-to-hotkeys
  "Listens to KEYDOWN events using goog.events and checks for Ctrl+S or 
  Cmd+S. When identified, sends a :save command on app channel."

      "Fetches document titles and starts the asynchronous command event 
      dispatch loop which handles all major app state changing events.
      Also attaches a KEYDOWN event listener to the page, for hot keys."
      (om/update! app :titles (p/get-all-titles))
      (let [channel (:channel app)]
        (go-loop []
          (let [[command params] (<! channel)]
            (dispatch command params app)
            (recur)))))
    om/IDidMount
    (did-mount [_]
      "Sets up event listeners when app has been properly loaded."
      (listen-to-hotkeys app)
      (synchronize-scroll))
    om/IRender
    (render [_]
      "Renders the app components in a container."
