   (fn [db [_ value]]
     (assoc db :username value)))
 
+(register-handler
+  :join-chat-room
+  (fn [db [_ room-id]]
+    (join-room room-id)
+    (assoc db :chat-room room-id)))
+
+(register-handler
+  :send-message
+  (fn [db [_ username message chat-room]]
+    (m/conj-in! fb-root [(-> chat-room (str/lower-case) (keyword))
+                         :messages]
+                [username message])
+    db))
+
 ;; -- View Components -------
 
 (defn username-input []

             :on-change #(dispatch [:set-username-input (-> % .-target .-value)])}]))

(defn message-form []
  (let [message  (reagent/atom "")
        username (subscribe [:username-input])]
    [:form {:on-submit (fn [e]
                         (.preventDefault e)
                         (firebase-swap! @fb-messages conj [@username @message]))}
     [:input {:type "text"
              :on-change #(reset! message (-> % .-target .-value))}]
     [:button {:type "submit"} "Send"]]))

  :username-input
  (fn [db _]
    (reaction (:username @db))))

(register-sub
  :current-chat-room
  (fn [db _]
    (reaction (:chat-room @db))))

(register-sub
  :chat-room-messages
  (fn [db _]
    (reaction (:messages @db))))

;; -- Event Handlers --------

