@wilkerlucio sadly not. I do have my action wrapped in a function , given as value for :action
. what I meant was, my mutate function is called twice, but my action is called only once, so that's ok. it was just suspicious, and I thought it might be a clue to why I am getting this error.
@wilkerlucio Here's the code:
(ns om.test
(:require [goog.dom :as gdom]
[om.next :as om :refer-macros [defui]]
[om.dom :as dom]))
(enable-console-print!)
(def app-state (atom {:search-text ""}))
(defmulti read om/dispatch)
(defmulti mutate om/dispatch)
(defmethod mutate `update-search-text [{:keys [state]} k {:keys [value]}]
(println "update-search-text" value)
{:action #(swap! app-state assoc :search-text value)})
(defmethod read :default [{:keys [state]} k p]
{:value (get @state k)})
(defui Customers
static om/IQuery
(query [this]
[:search-text])
Object
(render [this]
(let [{:keys [customers search-text]} (om/props this)]
;(println "Rendering Customers" (om/props this))
(dom/p nil
(dom/input #js {:value search-text
:type "text"
:onChange #(om/transact! this `[(update-search-text {:value ~(.. % -target -value)})])
}))
)))
(def customers (om/factory Customers))
(defui RootView
static om/IQuery
(query [this]
[:search-text])
Object
(render [this]
(let [{:keys [page] :as props} (om/props this)]
;(println "Rendering root" (om/props this))
(dom/div nil
(customers props)))))
(def reconciler
(om/reconciler
{:state app-state
:parser (om/parser {:read read :mutate mutate})
}))
(om/add-root! reconciler
RootView (gdom/getElement "app"))
when I use Customers
as root view, everything's fine of course