       (send-loop server-ch))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Handler
+
+(defmulti handle-event
+  (fn [event msg app owner] event))
+
+(defmethod handle-event :list [_ msg app owner]
+  (om/update! app :data msg))
+
+(defmethod handle-event :default [_ msg app owner])
+
+(defn create-handler [event app owner]
+  (fn [msg]
+    (handle-event event msg app owner)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Views
 
 (defn application [cursor owner]

    om/IWillMount
    (will-mount [_]
      (send-msg! {"id" (uuid)
                  "command" "list"} println))
    om/IRender
    (render [_]
      (html
       [:div.container
        [:div.page-header
         [:h1 "Org UI"]]]))))

(defn main []
  (setup-connection)

(defn receive-msg! [server-ch]
  (go-loop []
    (let [{:keys [message]} (<! server-ch)
          message (clojure.walk/keywordize-keys message)
          {:keys [in-response-to data]} message]
      (when-let [handler (get @requests in-response-to)]
        (handler data)
        (swap! requests dissoc uuid))
      (recur))))
