Om/Clojurescript:问题呈现重置应用程序状态

Om/Clojurescript: Issue rendering a reset application state

我正尝试在该小部件所需的数据到达时立即显示带有 om 的组件。我想出了以下(大致):

(def data (atom     {}))                                                               

(go (let [response (<! (http/get "../rest/ds" ))]                               
  (reset! data (:result (:body response)))))

(om/root
  (fn [app owner]                                                                  
    (reify
     om/IInitState
     (init-state [_]
       (prn "(1) returning initial state now")
       {:text "Hello world!"})
     om/IRenderState 
     (render-state [this state]                                                   
        (prn state) ; <-- here: not the state that I reset! before but the original state
        (do-something ...))))                                                  
  data
  {:target (. js/document (getElementById "app"))})

似乎 render-state 中的 state 从来不是我用 reset! 设置的,尽管似乎触发了重新渲染。我在这里用错了吗?当直接访问 render-state 中的 @data 时,它显示了我用 reset!.

设置的正确值

(prn state)中的状态为组件状态。原子 data 是应用程序状态,在您的组件中调用了 app.

(om/root
  (fn [app owner]  ; <- `app` is the application state                                                              
    (reify
     om/IInitState
     (init-state [_]
       (prn "(1) returning initial state now")
       {:text "Hello world!"})
     om/IRenderState 
     (render-state [this state]                                                   
        (prn app) ; <- refer to application state instead
        (do-something ...))))                          
  data
  {:target (. js/document (getElementById "app"))})