                       :error :empty-search))
           (om/transact! data 
             #(assoc % :current-state :loaded-final)))
-
         :else
         (om/transact! data
           #(assoc % :current-state :loaded

        ch  (chan)]
    (.send req nil #(put! ch %))
    (go (let [[v c] (alts! [t ch])]
          (case 
            ; timeout
            (= c t) 
            (>! ajax-chan {:error :timeout})

            ; Response error
            (not (= (.. v -meta -status) 200))
            (>! ajax-chan {:error :ajax})

            ; response OK
            (>! ajax-chan {:error false
                           :search-term search-term
                           :items (-> v
                                      (.. -response)
                                      (js->clj :keywordize-keys true)
                                      (#(filter #(= (:type %) "photo"))))
                           }))))))

(defn new-search [data ajax-chan query]
  (om/transact! data 
    #(assoc %
            :state :loading
            :before 0
            :current-search query
            :current-items [])))

;; Response Handler
;; -----------------------------------------------------------------------------

                 (= (:current-search @data) 
                    (:search-term response)))
      (cond
        ; error
        (:error response)
        (om/transact! data
          #(assoc % :current-state :error
                    :error (:error response)))
        ; empty response
        (empty? (:items response))
        (if (empty? (:current-items @data))
          (om/transact! data
