Reproduce: click submit with both variety of query (line 32):
-
(query [_] [:title [:current-user '_]])
-
(query [_] [:title {[:current-user '_] [:email]}])
The :current-user :email
can get inconsistent between views
(ns om-tutorial.transact | |
(:require [goog.dom :as gdom] | |
[om.next :as om :refer-macros [defui]] | |
[om.dom :as dom] | |
[cljs.pprint :refer [pprint]] | |
[clojure.zip :as zip])) | |
(enable-console-print!) | |
(def init-data | |
{:current-user {:email "bob.smith@gmail.com"} | |
:thing-a {:title "Thing A"} | |
:thing-b {:title "Thing B"}}) | |
(defmulti read om/dispatch) | |
(defmulti mutate om/dispatch) | |
(defmethod read :default | |
[{:keys [query state]} k _] | |
(let [st @state] | |
{:value (om/db->tree query (get st k) st)})) | |
(defmethod mutate 'user/update | |
[{:keys [state] :as env} _ _] | |
{:action (fn [] | |
(swap! state assoc-in [:current-user :email] "eyston@gmail.com") | |
(println "state" @state))}) | |
(defui Thing | |
static om/IQuery | |
(query [_] | |
; works | |
;[:title [:current-user '_]] | |
; does not work | |
[:title {[:current-user '_] [:email]}] | |
) | |
Object | |
(handle-submit-click [this e] | |
(om/transact! this ['(user/update) :current-user]) | |
) | |
(render [this] | |
(dom/li nil | |
(dom/pre nil (.stringify js/JSON (clj->js (om/props this)) nil 2)) | |
(dom/button #js {:onClick #(.handle-submit-click this %)} "Submit")))) | |
(def thing (om/factory Thing)) | |
(defui Root | |
static om/IQuery | |
(query [_] | |
[{:thing-a (om/get-query Thing)} | |
{:thing-b (om/get-query Thing)}]) | |
Object | |
(render [this] | |
(dom/div nil | |
(dom/h2 nil "Things!") | |
(dom/ul nil | |
(thing (-> this om/props :thing-a)) | |
(thing (-> this om/props :thing-b)))))) | |
(def reconciler | |
(om/reconciler | |
{:state init-data | |
:parser (om/parser {:read read | |
:mutate mutate})})) | |
(om/add-root! reconciler Root (gdom/getElement "app")) |