From 985f723c7cc18f8b537bf4f7c14236a0748ca605 Mon Sep 17 00:00:00 2001 From: Oliver Martell Date: Tue, 20 Feb 2018 12:34:42 +0000 Subject: [PATCH] [Fix #306] Add support for reloading code This adds `clojure.tools.namespace` to be able to reload code. It's a better alternative to `reload-all` as outlined [here](https://github.com/clojure/tools.namespace#reloading-code-motivation) and [here](https://github.com/tolitius/mount#the-importance-of-being-reloadable). If you run: - `refresh` will reload all changed namespaces with their latest definition. - `reset` will stop the current system first, then refresh, and restart the dependencies. --- env/dev/clj/user.clj | 25 ++++++++++++++++++++++--- project.clj | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/env/dev/clj/user.clj b/env/dev/clj/user.clj index b318a86..a70555a 100644 --- a/env/dev/clj/user.clj +++ b/env/dev/clj/user.clj @@ -1,15 +1,34 @@ (ns user (:require [mount.core :as mount] - [commiteth.figwheel :refer [start-fw stop-fw cljs]])) + [commiteth.figwheel :refer [start-fw stop-fw cljs]] + [clojure.tools.namespace.repl :as repl])) -(defn start [] +(repl/set-refresh-dirs "src" "dev" "test") + +(defn start + "Start all the application components" + [] (require 'commiteth.core) (mount/start-without (ns-resolve 'commiteth.core 'repl-server))) -(defn stop [] +(defn stop + "Stop all the application components" + [] (require 'commiteth.core) (mount/stop-except (ns-resolve 'commiteth.core 'repl-server))) +(defn refresh + "Reload the latest namespace definitions" + [] + (repl/refresh)) + +(defn reset + "Restart application after refreshing namespace definitions" + [] + (stop) + (repl/refresh :after 'user/start)) + (defn restart [] + "Restart without refreshing namespace definitions" (stop) (start)) diff --git a/project.clj b/project.clj index ac5d67a..71f2c74 100644 --- a/project.clj +++ b/project.clj @@ -124,6 +124,7 @@ [binaryage/devtools "0.9.7"] [figwheel-sidecar "0.5.14"] [org.clojure/tools.nrepl "0.2.13"] + [org.clojure/tools.namespace "0.2.11"] [com.cemerick/piggieback "0.2.2"] [sablono "0.8.1"]] :plugins [[com.jakemccrary/lein-test-refresh "0.14.0"]