简体   繁体   English

试剂不注册原子表

[英]Reagent does not register atom watch

I have simple newcomer's luminus with reagent application. 我有简单新人的Luminus公司试剂的应用。 I defined some component definition: 我定义了一些组件定义:

(def md-vals (atom nil))

(defn markdown [url]
  (GET
    (str js/context url)
    {:handler
     (fn [response]
       (swap! md-vals assoc url response)
       (js/alert (str "loaded\n" (subs response 1 100))))})
  (fn [] [:p (get @md-vals url "loading...")]))

It's usage as page component: 它用作页面组件:

(defn docs [] [markdown "/md/docs.md"])

And finally page binding: 最后页面绑定:

(defn init! []
  ...
  (render-component (docs)  (.getElementById js.document "docs")))

All works fine except atom state switch notification. 除原子状态切换通知外,一切正常。 At the time of successfull resource get i'm seeing alert message as supposed, but corresponding area of page does not switching. 在成功获得资源时,我看到了所谓的alert消息,但页面的相应区域没有切换。

Chrome debugger shows that at the moment of atom switch atom's watches property is empty ( null ), so no notification is fired. Chrome调试器显示,在原子切换时,atom的watches属性为空( null ),因此不会触发通知。

What could probably be wrong in my approach? 我的方法可能有什么问题?

You should use reagent.core/atom instead of regular Clojure atom . 你应该使用reagent.core/atom而不是常规的Clojure atom Add this to your namespace :require : 将其添加到您的命名空间:require

[reagent.core :as reagent :refer [atom]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM