In the local-state example in the om-cookbook, I'm able to update the counter using update-state! and set-state!, but not with transact!
I initialized project using chestnut template.
(def app-state (atom {:button-presses 0}))
These work
(defn clicks [data owner]
(om/update-state! owner [:button-presses] inc))
(defn clicks [data owner]
(let [value (om/get-state owner :button-presses)]
(om/set-state! owner :button-presses (inc value))))
This doesn't work
(defn clicks [data owner]
(om/transact! data :button-presses inc))
Call from IRenderState
om/IRenderState
(render-state [_ state]
(dom/div nil
(dom/button #js
{:onClick #(clicks data owner)}
"Click Moi")
(dom/br nil)
(dom/p nil
(str "Button Presses: " (:button-presses state)))))))
You are confusing application state and a component's state. Notice how
update-state!
andset-state!
takeowner
(the component) as argument, whiletransact!
andupdate!
take a cursor.Your above example actually acts on the cursor (
data
), not the state, but yourIRenderState
implementation is looking up:button-presses
on component's state. If you changed(:button-presses state)
to(:button-presses data)
everything should be fine.