0
我是Clojure的新手,並試圖設置一些簡單的Web路由。我希望這些路由在開發中重新加載所有相關的代碼,但不是在生產中。重新加載Clojure代碼/路由 - 使用符號與var的問題
我只能得到這個工作使用var的路線,而不是實際的符號。有人可以解釋我是否做錯了嗎?如果沒有,爲什麼需要var?
(def app-handler
(let [formats [:json-kw :edn :yaml-kw :yaml-in-html :transit-json :transit-msgpack]
wrapped-api (wrap-restful-format #'routes/api-routes :formats formats)
combined-routes (compojure.core/routes wrapped-api #'routes/html-routes)
with-defaults (wrap-defaults combined-routes api-defaults)]
(if (is-dev?)
; Development
(wrap-reload with-defaults)
; Production
with-defaults)))
(注#'routes/api-routes
和#'routes/html-routes
以上)。
這是因爲應用程序處理程序關閉了您的路由函數,並且如果您不使用該var,則無法爲提供您的應用程序處理程序作爲參數的服務器實例查看更新。看到[這個答案](http://stackoverflow.com/questions/28904260/dynamic-handler-update-in-clojure-ring-compojure-repl/28905078#28905078)爲更完整的描述和演示。 – noisesmith
@noisesmith感謝您的快速回復!另一個答案很好,我只是不知道要搜索什麼。與其他一些使用去參考值的方法相比,使用'var'會有什麼樣的有意義的性能影響? – Brandon
var被認爲是這樣做的標準方式(至少在dev期間)。 – noisesmith