 (defmethod event-msg-handler :chsk/recv
   [{:as ev-msg :keys [?data]}]
   (let [[topic payload] ?data]
-    (log (str "Push event from server: " ev-msg))
+    ;(log (str "Push event from server: " ev-msg))
+    (log (str "Push event from server: " topic))
     (when (= topic :event-manager/query-result)
       (handle-query-result (second ?data)))))
 

;; (om/add-root! reconciler
;;   Tester (gdom/getElement "app"))

(om/add-root! reconciler
  CompetitionsView (gdom/getElement "app"))

;; (defui Tester
;;   static om/IQuery
;;   (query [this]
;;          [{:app/competitions [:competition/name :competition/location {:competition/classes [:class/name]}]}])
;;   Object
;;   (render
;;    [this]
;;    (let [{:keys [app/competitions]} (get-in (om/props this) [:app/competitions 0])
;;          entity (first (:app/competitions (om/props this)))]
;;      ;;(log "Props =>")
;;      ;;(log (om/props this))
;;      (dom/div
;;       nil
;;       (dom/div
;;        nil
;;        (str "Competition 1 " (:competition/name entity)))
;;       (dom/div
;;        nil
;;        (str "Location " (:competition/location entity)))
;;       (dom/div
;;        nil
;;        (str "# classes " (count (:competition/classes entity))))
;;       (competition)
;;       (dom/div
;;        nil
;;        (dom/button
;;         #js {:onClick
;;              (fn [e]
;;                (test-query-click this)
;;                ;(chsk-send! [:event-manager/query [[:competition/name :competition/location]]])
;;                )}
;;         "Query"))))))



;; Server message handling

(defn handle-query-result [d]
  (let [clean-data (uidb/sanitize d)]
     ;(log clean-data)   
    ;(log (apply str (map :competition/name clean-data)))
                                        ;(d/transact! (d/db conn) )
    (d/transact! conn [clean-data])
    (log (d/q '[:find [(pull ?c [:class/name]) ...]
                :where
                [?e :competition/name "Rikstävling disco"]
                [?e :competition/classes ?c]]
              (d/db conn)))
    ;(d/transact! conn [{:db/id 1 :competition/name (apply str (map :competition/name clean-data))}])
    ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
