reloaded.repl
reloaded.repl copied to clipboard
Reloading not working as expected
Hello! For some reason I'm struggling a bit with hot reloading code from repl in a new project setup (lein).
in user.clj
(reloaded.repl/set-init!
#(make-system {}))
but (reset)
does not pick up changes (no change that I've could detect, after modifying stop and start component protoocols for ex, nor in web routes in the particular case I'm trying to impl)
Tried diffferent many things past in the hour (setting refresh dirs, using deref for the make-system symbol, etc) but the only way I managed to reload the code as I expected was to use this (refresh)
function:
(defn refresh
[]
(tools-ns/refresh-all)
(reloaded.repl/set-init!
#(make-system {}))
(init)
(go))
Not sure if here is the best place to ask, but if you some have some tips or experiene with related issues, I'd appreciate :)
Could you provide a little more information? What's in make-system
, for example? What does your project file look like? If you could set up a small project where the problems you're seeing could be reproduced, that would help a lot.
Hello James,
4 years after is never too late I guess... I was able to reproduce the reported issue.
Environment (somewhat irrelevant in that case):
* Java: OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
* Leiningen 2.9.1 on Java 11.0.10 OpenJDK 64-Bit Server VM
* Editor: GNU Emacs 27.1
* CIDER: 1.1.0snapshot
History
- Cloning repository: https://github.com/arnaudgeiser/reloaded.repl-issue-12
- Firing REPL (cider-jack-in)
- Loading the following namespace : https://github.com/arnaudgeiser/reloaded.repl-issue-12/blob/master/src/reloaded/repl_issue_12.clj
- Evaluating these expressions
(set-init! #(new-system))
(go)
-
Creating new system
is printed - Changing the following function definition (!!without evaluating it in the REPL!!)
(defn new-system []
(prn "Recreating new system")
(component/system-map))
- Evaluating this expression
(reset)
-
Creating new system
is printed
Expectation
Expected to see Recreating new system
printed.
However, it seems that clojure.tools.namespace.repl/refresh
is not the same as redefining the function in the REPL.
Actual
new-system
is always bounded to the previous definition
Impact
While it's surprising, the workaround is quite simple :
(reset)
(set-init! #(new-system))
(go)