 (ns unfolds.core
   (:require-macros [cljs.core.async.macros :refer [go]])
-  (:require [om.core :as om :include-macros true]
+  (: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 <!]]))
 

;; now with basic-list! (or not, does that help here - more like remove those?)
;; and go to lower-case?
;; should also have id in it
(defn naive-key-extractor [str]
    (vec (map first
              (filter #(= (second %) 1)
                      (frequencies (split-words (:text str)))))))

(defn make-word-map [str id]
  (zipmap (map first
               (filter #(= (second %) 1)
                       (frequencies (split-words str)))) (repeat id)))
;; then merge
;; should be elsewhere?

#_(defn item-view [item owner]
  (reify

;; 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 [(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)))))


(defn search [app owner]
  (let [search (-> (om/get-node owner "search")
