Skip to content

Instantly share code, notes, and snippets.

@ThomasDeutsch
Last active November 26, 2015 11:14
Show Gist options
  • Save ThomasDeutsch/36b080f41ad52605b864 to your computer and use it in GitHub Desktop.
Save ThomasDeutsch/36b080f41ad52605b864 to your computer and use it in GitHub Desktop.
why is the reader called twice, after the query params get modified?
(defmulti read om/dispatch)
(defmethod read :input-handler
[{:keys [query state]} k {:keys [query]}]
(println "read: input-handler")
(let [st @state]
{:value {:input-handler (clojure.string/join [query "+X"]) }}))
(defui SomeInput
static om/IQueryParams
(params [_]
{:str ""})
static om/IQuery
(query [_]
'[(:input-handler {:str ?str})])
Object
(render [this]
(dom/input
#js {:key "search-field"
:value (:str (om/get-params this))
:onKeyUp
(fn [e]
(om/set-query! this
{:params {:str (.. e -target -value)}}))})))
(def reconciler
(om/reconciler
{:state init-data
:parser (om/parser {:read read})}))
(om/add-root! reconciler SomeInput (gdom/getElement "app"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment