From e01b8218d79fdb8ee2ad2017b6266d4a79559591 Mon Sep 17 00:00:00 2001 From: Brian Noguchi Date: Wed, 5 Apr 2017 13:15:30 -0700 Subject: [PATCH] Add failing devcard test for GH-862 --- src/devcards/om/devcards/bugs.cljs | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/devcards/om/devcards/bugs.cljs b/src/devcards/om/devcards/bugs.cljs index daa7f0e5..f70e44fa 100644 --- a/src/devcards/om/devcards/bugs.cljs +++ b/src/devcards/om/devcards/bugs.cljs @@ -1025,6 +1025,58 @@ (dom/create-element "use" #js {:xlinkHref "#rectangle" :x "150"}))) +(def om-862-state (atom {:count 1})) +(def om-862-reconciler + (om/reconciler {:state om-862-state + :remotes [:remote] + :parser (om/parser + {:read (fn [{:keys [state]} key _] + {:value (get @state key)}) + :mutate (fn [{:keys [state]} key _] + {:value {} + :action #(swap! state + update :count inc) + :remote (= 'count/inc-by-each-remote + key)})}) + :send (fn [{:keys [remote]} cb] + (when remote + (let [resp {:count (inc (:count @om-862-state))} + query [:count]] + (cb resp query remote))))})) + +(defui om-862-Root + static om/IQuery + (query [this] + [:count]) + Object + (render [this] + (let [props (om/props this)] + (dom/div nil + (dom/div + nil + "Clicking first on should not + prevent from scheduling a + reconcile! Try clicking first on and + then try clicking on .") + (dom/button + #js {:onClick #(om/transact! + this '[(count/inc-by-each-remote)])} + "Should increment by 2") + (dom/button + #js {:onClick #(om/transact! + this '[(count/inc-only-client)])} + "Should increment by 1") + (dom/div nil (:count props)))))) +; Override om/*raf* to force the race condition that causes the abberant +; om-862 behavior +(set! om/*raf* (fn [f] + (println "*raf* override called") + (f))) +(defcard om-862-card + (dom-node + (fn [_ node] + (om/add-root! om-862-reconciler om-862-Root node)))) + (comment (require '[cljs.pprint :as pprint])