   (om/reconciler
    {:state  init-data
     :parser (om/parser {:read read :mutate mutate})}))
-

(ns discuss.parser
  (:require [om.next :as om]))

(def init-data {:search/results []})

;; -----------------------------------------------------------------------------
;; Parsing

(defmulti read (fn [env key params] key))
(defmethod read :default
  [{:keys [state] :as env} key params]
  (let [st @state]

      {:value value}
      {:value :not-found})))

#_(defmethod read :item/by-url
  [{:keys [state]} _ {:keys [url]}]
  (let [st @state
        item (for [item (get st :discussion/items) :when (= url (:url item))] item)]
    item))
;; (read {:state (om/app-state scarf.core/reconciler)} :color/by-id {:id 1})


(defmulti mutate om/dispatch)
(defmethod mutate 'search/results [{:keys [state]} _ {:keys [results]}]
  {:action (fn [] (swap! state assoc :search/results results))})

(defmethod mutate 'discussion/items [{:keys [state]} _ {:keys [items]}]
  {:action (fn [] (swap! state assoc :discussion/items items))})

(defmethod mutate 'discussion/bubbles [{:keys [state]} _ {:keys [bubbles]}]
  {:action (fn [] (swap! state assoc :discussion/bubbles bubbles))})

;; -----------------------------------------------------------------------------

