When using om, (prior to om-next), I am getting an error when attempting to make updates outside of the render phase:
cljs.user=> (require '[om.core :as om :include-macros true])
cljs.user=> (def state (atom {:foo {:bar true}}))
#'cljs.user/state
cljs.user=> (def state-cursor (om/root-cursor state))
#'cljs.user/state-cursor
cljs.user=> (om/update! state-cursor [:foo :bar] false)
#object[Error Error: No protocol method INotify.-notify! defined for type cljs.core/Atom: [object Object]]
Error: No protocol method INotify.-notify! defined for type cljs.core/Atom: [object Object]
at cljs$core$missing_protocol (http://localhost:10555/js/out/cljs/core.js:290:9)
at om$core$_notify_BANG_ (http://localhost:10555/js/out/om/core.js:841:34)
at om$core$notify_STAR_ (http://localhost:10555/js/out/om/core.js:2518:30)
at om$core$transact_STAR_ (http://localhost:10555/js/out/om/core.js:1070:29)
at om.core.MapCursor.om$core$ITransact$_transact_BANG_$arity$4 (http://localhost:10555/js/out/om/core.js:2042:31)
at om$core$_transact_BANG_ (http://localhost:10555/js/out/om/core.js:770:15)
at Function.om.core.transact_BANG_.cljs$core$IFn$_invoke$arity$4 (http://localhost:10555/js/out/om/core.js:4074:32)
at om$core$transact_BANG_ (http://localhost:10555/js/out/om/core.js:4044:31)
at Function.om.core.update_BANG_.cljs$core$IFn$_invoke$arity$3 (http://localhost:10555/js/out/om/core.js:4135:31)
at om$core$update_BANG_ (http://localhost:10555/js/out/om/core.js:4105:29)
Instead of the error: Error: No protocol method INotify.-notify! defined for type cljs.core/Atom
, I expect this to update the state
atom to (atom {:foo {:bar false}})
. How do I fix this?
The problem was that I needed to call
(om/ref-cursor)
on the root cursor before passing it toom/transact!
orom/update!
. Doing this fixed my problem: