 ;; read operations should follow a mutation. :tempids will be discussed later. 
 ;; Mutations can easily change multiple aspects of the application (think Facebook "Add Friend"). 
 ;; Adding :value with a :keys vector helps users identify stale keys which should be re-read.
+;; (defmethod mutate 'app/name
+;;   [{:keys [state]} _ _]
+;;   {:value {:keys [:competition/name]}
+;;    :action (fn [] (d/transact! state [{:db/id 1 :competition/name "B"}]))})
+
 (defmethod mutate 'app/name
   [{:keys [state]} _ _]
-  {:value {:keys [:competition/name]}
-   :action (fn [] (d/transact! state [{:db/id 1 :competition/name "B"}]))})
+  {:value {:keys [:app/competitions]}
+   :action (fn [] (chsk-send! [:event-manager/query [[:competition/name :competition/location]]]))})
 
 (defn test-query-click [t]
   (do

  [{:keys [state query] :as env} key params]
  {:value (do
            ;(log (str "Env: " env " --- Key : " key " --- Params" params))
            (d/q '[:find [(pull ?e ?selector) ...]
                   :in $ ?selector
                   :where [?e :competition/name]]

    ;;   #js {"Content-Type" "application/transit+json"})
    ))

(defn sente-post []
  (fn [{:keys [remote] :as env} cb]
    (do
      (log "Env > ")
      (log env)
      (log (str "Sent to Tango Backend => " remote))
      (chsk-send! [:event-manager/query [[:competition/name :competition/location]]]))))

(def reconciler
  (om/reconciler
    {:state conn
     :remotes [:remote]
     :parser (om/parser {:read read :mutate mutate})
     :send (sente-post) ;(fn [x y] (log (str "Sending to server: x" x " y: " y)))
     }))

;; (om/add-root! reconciler
