                ))))
 
 (defn init []
-  (let [el (. js/document (getElementById "om-app"))]
+  (let [el (. js/document (getElementById "om-app"))
+        search (chan)]
     (om/root app-view app-state
-             {:target el})))
+             {:target el
+              :shared {:search-channel search}})))
 
 (.addEventListener js/window "load" init)

               )))))

;; XXX need to do some url encoding here, I rather suspect
(defn query-string-for-map [h]
  (string/join "&"
            (map (fn [[k v]] (str (name k) "=" v)) h)))

(defn send-query [term filters channel]
  (.send XhrIo (string/join "?" ["/tracks.json" (query-string-for-map filters)])
         (fn [e]
           (let [xhr (.-target e)
                 o (.getResponseJson xhr)
                 r (js->clj o)]
             (put! channel r)))
         "POST"
         term
         {"Content-Type" "text/plain"}
         ))

(defn send-search-xhr [term owner {:keys [new-results search-term]}]
  (let [filters (:filters @app-state)]
    (om/set-state! owner :search-term term)
    (send-query term filters new-results)))

(defn filters-view [app owner]
  (reify
    om/IWillMount

                 [title artist album duration button]
                 [artist album title duration button]))))))


(defn xhr-search [term]
  (let [channel (chan)]
    (.send XhrIo (string/join "?" ["/tracks.json" ])
           (fn [e]
             (let [xhr (.-target e)
                   o (.getResponseJson xhr)
                   r (js->clj o)]
               (put! channel r)))
           "POST"
           term
           {"Content-Type" "text/plain"}
           )
    channel))

(defn results-view [app owner]
  (reify
    om/IWillMount
    (will-mount [_]
      (let [channel (om/get-shared owner :search-channel)]
        (go (loop []
              (let [search-for (<! channel)
                    tracks (<! (xhr-search search-for))
                    sorted (sort-by
                            #(vector (get % "artist")
                                     (get % "album")
