gpt4 book ai didi

clojure - Figwheel 没有检测到我的代码中的大部分更改

转载 作者:行者123 更新时间:2023-12-02 13:39:44 24 4
gpt4 key购买 nike

Figwheel 可以很好地显示下面的代码。但我必须刷新页面才能看到任何更改。 Figwheel 必须改变什么才能显示变化?是否有命令可以强制重绘而不丢失应用程序状态?

顺便说一句:Chrome 已禁用缓存true,并且保存文件时会出现 CLJS 图标

(defn simple-example []
[ui/mui-theme-provider {:mui-theme (get-mui-theme
{:palette {:text-color (color :blue800)}})}
[:div
[ui/app-bar {:title "Hi all"
:icon-class-name-right "muidocs-icon-navigation-expand-more"}]
[ui/paper
[:div
[ui/tabs
[ui/tab {:label "Menu" :value "0"}
[:div "Hello world"]]]]]]]))

(defn ^:export run []
(render [simple-example]
(js/document.getElementById "app"))))

最佳答案

来自docs :

Setting :figwheel true or :figwheel { :on-jsload "example.core/reload-hook" } will automagically insert the figwheel client code into your application. If you supply :on-jsload the name of a function, that function will be called after new code gets reloaded.

重新加载钩子(Hook)以及试剂配置的示例:

(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-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 有一个 ID 为 app 的节点并调用 initproject.cljs 指定 on-jsload 如下:

:cljsbuild
{:builds
[{:id "dev"
:source-paths ["src/cljs"]
:figwheel {:on-jsload "your-project-name.core/mount-root"}
#_(...)}}

这绝对应该更新页面并更改组件。如果它没有达到您想要的效果,我可能误解了您的问题。

关于clojure - Figwheel 没有检测到我的代码中的大部分更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46287101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com