     (:import goog.History))
 
 ;; -------------------------
-;; Re-frame data
+;; Re-frame subscriptions
 
 (re-frame/register-sub        ;; a new subscription handler
  :phones             ;; usage (subscribe [:phones])
  (fn [db]
+   ;; extracts the phones property from the db
    (reaction (:phones @db))))  ;; pulls out :phones
 
 (re-frame/register-sub

     [:input {:on-change #(re-frame/dispatch [:search-input-entered (-> % .-target .-value)])}]]))

(defn mark-selected
  [props order-prop current-prop-value]
  (if (= order-prop current-prop-value)
    (reagent/merge-props props {:selected "selected"})
    props))

(defn order-by-component
  []
  (let [order-prop (re-frame/subscribe [:order-prop])]
    (fn []

   app-state))

(re-frame/register-handler
 :process-phone-detail-response
 (fn
   ;; store info for the specific phone-id in the db
   [app-state [_ phone-id response]]
   (assoc-in app-state [:phone-details (keyword phone-id)] response)))

(re-frame/register-handler
 :process-phone-detail-bad-response
 (fn
   [app-state [_ [phone-id response]]]
   (println "Error getting phone detail for id: " phone-id)
   (println response)
   app-state))

(re-frame/register-handler
 :load-phone-detail
 (fn
   ;; fetch information for the phone with the given phone-id
   [app-state [_ phone-id]]
   (ajax/GET (str "phones/" phone-id ".json")
             {:handler #(re-frame/dispatch [:process-phone-detail-response phone-id %1])
              :error-handler #(re-frame/dispatch [:process-phone-detail-bad-response phone-id %1])
              :response-format :json
              :keywords? true})
   app-state))

(re-frame/register-handler
 :initialise-db             ;; usage: (dispatch [:initialise-db])
 (fn
   [_ _]                   ;; Ignore both params (db and v).
