       om/IWillMount
       (will-mount [_]
         (let [ajax-chan (chan 1)]
-          (om/set-state! owner :ajax-chan ajax-chan) 
           (async-response-loop data ajax-chan)
           (async-window-scroll data ajax-chan)
           (async-window-resize data)
-          (setup-navigation data ajax-chan)))
+          (setup-navigation    data ajax-chan)))
       om/IRenderState 
       (render-state [this local-state]
         (dom/div nil
                  (case (:current-state data)
-                   :search  (om/build render-search data
-                                      {:state {:ajax-chan (om/get-state owner :ajax-chan)}})
+                   :search  (om/build render-search data)
                    :loading (om/build render-loading data)
                    :loaded  (om/build render-loaded data)
                    :loaded-final (om/build render-loaded data)


(defn async-window-scroll [data ajax-chan]
  (.addEventListener js/window "scroll" 
                     (fn []
                       (when
                         (and
                           (= :loaded (:current-state @data))
                           (let [body (.. js/document -body)
                                 html  (.. js/document -documentElement)
                                 height (max (.. body -scrollHeight)
                                             (.. body -offsetHeight)
                                             (.. html -clientHeight)
                                             (.. html -scrollHeight)
                                             (.. html -offsetHeight)
                                             )]
                             (> 100
                                (- height
                                   (+ (.. js/window -innerHeight)
                                      (.. js/window -scrollY))))))
                         (om/transact! data #(assoc % :current-state :loading))
                         (go (async-search @data ajax-chan))))))

(defn async-window-resize [data]
  (.addEventListener 
    js/window "resize"
    (fn []
      (om/transact! data #(assoc % :window-width (.. js/window -innerWidth))))))


(defn setup-navigation [data ajax-chan]

  (secretary/set-config! :prefix "#")

  (defroute search-route "/search/:query" [query]
    (new-search data query ajax-chan))

  (defroute index-route "/" []
    (om/transact! data reset-state))

  (om/transact! data #(assoc % :routes
                             {:index index-route
                              :search search-route}))

  (let [h (History.)]
    (goog.events/listen h EventType/NAVIGATE #(secretary/dispatch! (.-token %)))

                      (dom/button
                        #js {:onClick (fn [e]
                                        (.preventDefault e)
                                        (set! js/window.location.hash "")
                                        )}
                        "Reset")
                      ; loading
