                (apply dom/div nil
                       (prepare-item (:item/text item)))))))
 
-(defn item-add-view [item owner {:keys [navigate event]}]
+(defn item-add-view [item owner]
   (reify
     om/IRenderState
     (render-state [_ state] ;; keys chan as etc?
-      (let [opts {:navigate navigate
-                  :event event}]
+      (let [event-chan (om/get-state owner [:event-chan])]
         (dom/div #js {:id "item-add-view"}
         (dom/div #js {:id "item-info"}
                  (dom/div #js {:className "item-name editable"}

  (reify
    om/IInitState
    (init-state [_]
      {:navigate (chan)
       :event (chan)})

    om/IWillMount
    (will-mount [_]

      (defroute "/" []
        (om/update! app :route
                    [:view-item "ea72343d-89dc-4dfc-85af-25e1113b0948"]))

      (defroute "/new" []
        (om/update! app :route [:add-item]))

      (defroute "/search" []
        (om/update! app :route [:search-item]))

      (defroute "/:id" {id :id}
        (om/update! app :route [:view-item id])
        (put! (om/get-state owner :event) {:op :get :data id}))

      (.setEnabled history true)

      ;; routing loop
      (go (loop []
            (let [id (<! (om/get-state owner :navigate))]
              (cond
               (= id :new)
               (do
                 (.setToken history "/new")
                 (om/update! app :current-item
                             {:item/title "New item"
                              :item/text ""}))

               (= id :search)
               (.setToken history "/search")))
            (recur)))

      ;; event loop
      (go (loop []
            (let [event (om/get-state owner :event)
                  {:keys [op data]} (<! event)]
              (condp = op

                :create
                (let [data (<! (util/edn-chan
                                {:method :post :url "/items"
                                 :data data}))]
                  (.setToken history (str "/" (:item/id data))) ;; XXX
                  (om/transact! app :current-item #(merge % data)))

                :get

                :search
                (let [data (<! (util/edn-chan
                                {:url (str "/search/" (:subs data))}))]
                  ;;(.setToken history (str "/search/" (:subs data)))
                  (om/update! app [:items] data)))))))

      (defroute "/" []
        (om/update! app :route
                    [:view-item "ea72343d-89dc-4dfc-85af-25e1113b0948"]))

      (defroute "/new" []
        (om/update! app :route [:add-item]))

      (defroute "/search" []
        (om/update! app :route [:search-item]))

      (defroute "/:id" {id :id}
        (om/update! app :route [:view-item id])
        (put! (om/get-state owner [:chans :event-chan]) {:op :get :data id}))

      (.setEnabled history true))
    
    om/IRenderState
    (render-state [_ {:keys [chans]}]
      (let [route (:route app)
            opts {:init-state chans}
            event-chan (om/get-state owner [:chans :event-chan]) ;; XXX
            ]
        ;; menu bar
        (dom/div nil
          (dom/p nil
