          (-remove-todos model :completed?)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;; View model
+(def -visibility-spec
+  [{:key :all :title "All" :href "#" :token ""}
+   {:key :active :title "Active" :href "#/active" :token "/active"}
+   {:key :completed :title "Completed" :href "#/completed" :token "/completed"}])
+
+(defn -visibility
+  [model]
+  (->> -visibility-spec
+       (filter #(= (:token %) (::routing/token model)))
+       first
+       :key))
+
 (defn view-model
   [model]
   ; reactions are extracted for better perfromance, e.g.:
   ; when input field changes most reactions will not be recalculated,
   ; because todos stay the same
   (let [todos (reaction (:todos @model))
-        visibility (reaction (:visibility @model))]
+        visibility (reaction (-visibility @model))]
     (-> model
-        (ui/track-keys [:field :visibility])
-        (assoc :has-todos? (reaction (-> @todos count pos?))
+        (ui/track-keys [:field])
+        (assoc :visibility visibility
+               :has-todos? (reaction (-> @todos count pos?))
                :todos (reaction (filter (case @visibility
                                           :all (constantly true)
                                           :active (complement :completed?)


(defn init
  []
  {:field      ""
   :visibility :all
   ; list of maps
   :todos      (list (-init-todo 1 "Finish this project")
                     (-init-todo 2 "Take a bath"))
   :next-id    3})

(defn -update-todos*
  [model pred f & args]

         ; do nothing, only for a demo
         :sample-action model

         [:update-field val]
         (assoc model :field val)

