   (get-in @app-state [:user :logged-in?]))
 
 
+;;;; State changing
+(defn update-state-item!
+  "Get the cursor for given key and select a field to apply the function to it."
+  [col key f]
+  (om/transact! (get-cursor col) key f))
+
+(defn update-state-map!
+  "Get the cursor for given key and update it with the new collection of data."
+  [key col]
+  (let [state (get-cursor key)]
+    (om/transact! state (fn [] col))))
+
+
 ;;;; References
 (defn get-references
   "Returns a list of references which were received from the discussion system."

                             :csrf       nil
                             :statement  ""
                             :selection  nil
                             :logged-in? false}
                :clipboard  {:selections nil
                             :current    nil}

  ([id col]
   (first (filter #(= (str->int id) (:uid %)) col)))
  ([id]
   (get-reference id (get-references))))

(defn save-selected-reference!
  "Saves the currently clicked reference for further processing."
  [ref]
  (update-state-item! :user :selected-reference (fn [_] ref)))

(defn selected-reference
  "Returns the currently selected reference."
  []
  (get-in @app-state [:user :selected-reference]))


;;;; CSRF Token
