从文档:
设置:figwheel true
或:figwheel { :on-jsload "example.core/reload-hook" }
将自动将figwheel客户端代码插入您的应用程序。如果您提供:on-jsload
函数的名称,则该函数将在新代码重新加载后被调用。
一个示例 reload hook 加上 Reagent 的配置:
(ns your-namespace.core
(:require [reagent.core :as r]))
(defn render [view]
(let [node (.getElementById js/document "app")]
(r/render-component view node)))
(defn rerender []
(let [node (.getElementById js/document "app")]
(r/unmount-component-at-node node)
(render [:div "Reloading"]))
(defn ^:export reload []
(rerender))
然后在你的project.clj
:
:cljsbuild {:builds {:dev {:source-paths ["src"]
:figwheel {:on-jsload "your-namespace.core/reload"}}}
/编辑
请注意,re-frame 使用 Reagent。在重新框架的情况下,我建议从re-frame-template
. 例如,
lein new re-frame your-project-name # options, e.g., +re-frisk +cider
这将给出core.cljs
如下默认值:
(defn dev-setup []
(when config/debug?
(enable-console-print!)
(println "dev mode")))
(defn mount-root []
(re-frame/clear-subscription-cache!)
(reagent/render [views/main-panel]
(.getElementById js/document "app")))
(defn ^:export init []
(re-frame/dispatch-sync [:initialize-db])
(dev-setup)
(mount-root))
index.html
有一个 idapp
和 calls的节点init
。并project.cljs
指定on-jsload
如下:
:cljsbuild
{:builds
[{:id "dev"
:source-paths ["src/cljs"]
:figwheel {:on-jsload "your-project-name.core/mount-root"}
#_(...)}}
这绝对应该使用更改的组件更新页面。如果它不符合您的要求,我可能误解了您的问题。