Clojurescript 将装入的transact-app状态无效
这个问题最好用一个例子来解释:Clojurescript 将装入的transact-app状态无效,clojurescript,om,Clojurescript,Om,这个问题最好用一个例子来解释: ;; create a basic om app. lein new mies-om om-tut lein cljsbuild auto. 然后粘贴以下代码(在core.cljs中) 中的代码将挂载实际上正在执行,如果您插入println函数,您将看到这一点。不清楚的是为什么渲染循环只调用一次。另一方面,如果您包装om/update在go块中,然后它按预期工作: ;; add [org.clojure/core.async "0.1.346.0-17112a-
;; create a basic om app.
lein new mies-om om-tut
lein cljsbuild auto.
然后粘贴以下代码(在core.cljs
中)
中的代码将挂载
实际上正在执行,如果您插入println
函数,您将看到这一点。不清楚的是为什么渲染循环只调用一次。另一方面,如果您包装om/update代码>在go
块中,然后它按预期工作:
;; add [org.clojure/core.async "0.1.346.0-17112a-alpha"] to your deps in project.clj
(ns om-tut.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [om.core :as om :include-macros true]
[cljs.core.async :refer [put! chan <! to-chan close!]]
[om.dom :as dom :include-macros true]))
(def app-state (atom {:text "Hello world!"}))
(om/root
(fn [app owner]
(reify
om/IWillMount
(will-mount [_]
(go
(om/update! app :text "Success!!")))
om/IRender
(render [_]
(dom/div nil (app :text )))))
app-state
{:target (. js/document (getElementById "app"))})
;;将[org.clojure/core.async“0.1.346.0-17112a-alpha”]添加到project.clj中的DEP中
(ns om-tut.core)
(:需要宏[cljs.core.async.macros:refere[go]])
(:require[om.core:as-om:include macros true]
[cljs.core.async:参考[put!chan]
问题是:既然我更新了应用程序状态,为什么将挂载
不会触发新的渲染循环?我喜欢在需要时使用go
块,但我不明白为什么我必须将这个简单的示例包装在块中。它认为将挂载不是更新光标的好地方。
使用:fn选项调用om/build将实现您想要实现的目标
组件仅渲染一次,并使用更新的光标
(om/build mycomponent data{:fn#(assoc%:text“Success!”)}
也注意到了这一点,而且它似乎与您正在使用的om版本有某种关联。[om“0.8.0-beta3”]
和transact!当我获得旧值时,内部的光标将挂载。但是,如果我切换到[om“0.7.3”]
lein cljsbuild clean
之后的相同代码将呈现新值。这个问题将在github上讨论
;; add [org.clojure/core.async "0.1.346.0-17112a-alpha"] to your deps in project.clj
(ns om-tut.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [om.core :as om :include-macros true]
[cljs.core.async :refer [put! chan <! to-chan close!]]
[om.dom :as dom :include-macros true]))
(def app-state (atom {:text "Hello world!"}))
(om/root
(fn [app owner]
(reify
om/IWillMount
(will-mount [_]
(go
(om/update! app :text "Success!!")))
om/IRender
(render [_]
(dom/div nil (app :text )))))
app-state
{:target (. js/document (getElementById "app"))})