 ;; before items looked like this
 ;; :items [{:id "foo" :text "bar"}] ;; dammit!
 
+;; util fn
+(defn in?
+  "true if seq contains elm"
+  [seq elm]
+  (some #(= elm %) seq))
+
 (def id-atom (atom -1))
 (swap! id-atom inc) ;; first item, 0
 (swap! id-atom inc) ;; second item, 1
 (swap! id-atom inc) ;; third item, 2
 
+;; Let's just start with all the words. Leaving freqs in.
+(defn make-word-map [[id str]]
+  (zipmap (map first
+               (frequencies (split-words str)))
+          (repeat [id])))
+
 (defn add-item [app owner]
   (let [new-item-text (-> (om/get-node owner "new-item")
                      .-value)
-        new-item {:id (swap! id-atom inc) :text new-item-text}]
+        new-item [(swap! id-atom inc) new-item-text]]
     (when new-item
+      (om/transact! app :word-map #(merge-with union % (make-word-map new-item)))
       (om/transact! app :items #(conj % new-item)))))
-;; Do this when adding
-;;(str (naive-key-extractor item) ", ")
+
 
 (defn search [app owner]
   (let [search (-> (om/get-node owner "search")

               (apply dom/ul nil
                      (om/build-all visible-item-view
                                    ;; into vec?
                                    (filter (fn [[i _]] (contains? (:visible app) i)) (:items app))))))))

(defn main []
  (om/root app-view

(ns unfolds.core
  (:require-macros [cljs.core.async.macros :refer [go]])
  (:require [clojure.set :refer [union]]
            [om.core :as om :include-macros true]
            [om.dom :as dom :include-macros true]
            [cljs.core.async :refer [put! chan <!]]))

