   :visible-todos
   (fn
     [db _]
-
     (let [todos     (reaction (:todos @db))
-          showing   (reaction (:showing @db))
-          _         (println @showing)
-          filter-fn (case @showing
-                      :active (complement :done)
-                      :done :done
-                      :all identity)]
-    (reaction (filter filter-fn (vals @todos))))))
+          showing   (reaction (:showing @db))]
+    (reaction (filter (filter-fn-for @showing)
+                      (vals @todos))))))
 
 
 (register-sub
   :completed-count
   (fn
     [db _]
-    (reaction (->> (:todos @db)
-                   (filter :done)
-                   count))))
-
-(register-sub
+    (reaction (completed-count (:todos @db)))))
+
+
+#_(register-sub
   :footer-stats
   (fn
     [db _]
     (let [todos (reaction (:todos @db))
           completed-count (subscribe [:completed-count])
-          active-count    (reaction (- (count @todos) @completed-count))
+          active-count    (reaction (- (count (vals @todos)) @completed-count))
           showing         (reaction (:showing @db))]
-      (reaction [@active-count @completed-count @showing]))))  ;; tuple
+      (reaction
+        [@active-count @completed-count @showing]))))  ;; tuple
+
+(register-sub
+  :footer-stats
+  (fn
+    [db _]
+    (reaction
+      (let [todos (:todos @db)
+            completed-count (completed-count todos)
+            active-count    (- (count todos) completed-count)
+            showing         (:showing db)]
+        [active-count completed-count showing]))))  ;; tuple
+
 
 
 ;; -- Components ---------

(def todo-edit (with-meta todo-input
                 {:component-did-mount #(.focus (reagent/dom-node %))}))

(defn stats-footer []
  (let [footer-stats (subscribe [:footer-stats])]
    (fn []
      (let [[active done filter] @footer-stats
            props-for (fn [filter-kw]
                        {:class (if (= filter-kw filter) "selected")
                         :on-click #(dispatch [:set-showing filter-kw])})]
        [:footer#footer
         [:div
          [:span#todo-count

;;
;; Middleware means our handlers are pure and simple.
;;
(def todo-middleware (comp (path [:todos])
                           debug
                           trim-v ))

;; -- Handlers -------------

