     {:state conn
      :parser (om/parser {:read read :mutate mutate})}))
 
-; Load all items from API
+; Load all sorts from API
 (edn-xhr {:method "GET"
-          :path "/items"
+          :path "/sorts"
           :on-complete (fn [data]
                          (d/transact! conn data))})
 

; Reader for state
(defmulti read om/dispatch)

(defmethod read :items
  [{:keys [state query]} key params]
  {:value (d/q '[:find [(pull ?e [*]) ...]
                 :where [?e :item/name]]
               (d/db state) query)})

; Mutator for state
(defmulti mutate om/dispatch)

; Add a single item
; Persists to the backend API first, before adding the complete
; item from the API response to the locale state cache.
; TODO: Add to local state cache immediately, updating with response
; data and reverting local transaction if persisting fails
(defmethod mutate 'items/add
  [{:keys [state]} _ entity]
  {:value {:keys [:items]}
   :action (fn []
             (edn-xhr {:method "POST"
                       :path "/items"
                       :data entity
                       :on-complete
                       (fn [data]
                         (d/transact! state [data]))}))})

; Scavenger items list
(defui ItemsList
  Object
  (render [this]
    (let [items (om/props this)]
      (apply dom/ul nil
        (map
          (fn [item]
            (dom/li nil (:item/name item)))
          items)))))

(def items-list (om/factory ItemsList))

(def google-map (js/React.createFactory js/GoogleMapReact))

; Keep state property for name text in AddItem component instance up to date
(defn update-state [component event]
  (om/update-state! component assoc
    :name-text (.. event -target -value)))

(defui AddItem
  static om/IQuery
  (query [this]
    [:items])
  Object
  (render [this]
    (dom/div nil

             (fn [e]
               (let [value (om/get-state this :name-text)]
                 (om/transact! this
                    `[(sorts/add {:sort/name ~value})])))}
        "Add sort!"))))

(def add-sort (om/factory AddSort))

; Main application component
(defui App
  static om/IQuery
  (query [this]
    [:sorts])
  Object
  (render [this]
    (let [{:keys [sorts]} (om/props this)]
      (dom/div nil
        (dom/h1 nil "Scavenger sorts")
        (sorts-list sorts)
        (add-sort)

(def app (om/factory App))

