当使用om时(在om-next之前),当我试图在渲染阶段之外进行更新时,我得到了一个错误:
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)我希望这会将state原子更新为(atom {:foo {:bar false}}),而不是错误:Error: No protocol method INotify.-notify! defined for type cljs.core/Atom。我该如何解决这个问题?
发布于 2016-02-18 03:02:15
问题是,在将根游标传递给om/transact!或om/update!之前,我需要在根游标上调用(om/ref-cursor)。这样做解决了我的问题:
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! (om/ref-cursor state-cursor) [:foo :bar] false)
nil
cljs.user=> state
#object [cljs.core.Atom {:val {:foo {:bar false}}}]https://stackoverflow.com/questions/35465414
复制相似问题