0

我正在使用 Leiningen 2.5.2(Java 1.8.0_45-internal Open JDK 64-bit)和试剂模板(即lein new reagent foo)。

这可以lein figwheel按预期运行。

接下来,我要做的第一件事是将“视图”函数分解为单独的文件并将它们添加到应用程序命名空间:

core.cljs 片段:

;; -------------------------
;; Views

(:require home-page)

home-page.cljs(整个文件):

(ns foo.core)

(defn home-page []
  [:div [:h2 "Welcome to foo"]
   [:div [:a {:href "#/about"} "go to about page"]]])

当我在浏览器(铬或火狐)中查看应用程序时,它卡在“ClojureScript 尚未编译!” 尽管看似在终端中成功编译。如果我在 figwheel REPL 中输入命令,当它在浏览器中运行时,我会看到绿色的 Clojure 徽标,因此我知道它已连接。

几个月前我在一个试剂应用程序中工作过——发生了什么?我应该如何分离我的视图代码?(单个文件是无法管理的;这是很多打嗝。)

4

1 回答 1

3

如果你真的只有(:require home-page)core.cljs中的那一行,这应该是罪魁祸首。冒号符号:require仅在带有 . 的命名空间声明中有效ns。此外,您在错误的文件(home-page.cljs,而不是 core.cljs)中声明了核心命名空间。查看这篇关于 Clojure中的命名空间的文章以获得详尽的解释。

您将需要 core.cljs 中的以下内容:

(ns foo.core
  (:require [foo.home-page :as hp :refer [home-page]]))
.... more core.cljs code ...

然后简单地在 home-page.cljs 中:

(ns foo.home-page
  (:require ....reagent namespaces as needed ....

(defn home-page [] ....
于 2015-09-22T06:36:07.203 回答