Closed markokocic closed 4 months ago
Once merged, one would also need to update all route definitions, e.g. in modules and docs to take advantage of reloading.
I could not find a way to enable reloading of routes while still keeping route definitions returning vectors,
Moved dev mode check in init-key for :router/core
and changed (vec (map ...
to (mapv ...
Just pushed up a new template with the changes.
@markokocic Hi I wanted to try this. I didn't read through the Reitit docs on it but couldn't get any re-evaluations I did take effect. Do you need to re-eval the actual handler or does any function down the call chain suffice? (I would guess so) I created a new project with clj-new.
HI @gerdint , you need to re-evaluate only what you changed in repl, cider, nrepl for your changes to be picked up. Just saving the file does nothing.
You also need ot make sure init-key function for your route returns a fn instead of vector, like for example in api:
(defmethod ig/init-key :reitit.routes/api
[_ {:keys [base-path]
:or {base-path ""}
:as opts}]
(fn [] [base-path route-data (api-routes opts)]))
Hmm, this is exactly what I (thought) I did. Will have another go. It would save a lot of cpu cycles not to have to (reset)
all the time.
I forgot to add that you have to be in the dev
mode for the hot-reloading of routes, for example clj -M:dev:cider
In prod mode, routes are cached.
Fixes #48 by implementing reloading of routes as recommended by
reitit
in https://github.com/metosin/reitit/blob/master/doc/advanced/dev_workflow.mdTo take advantage of reloading, one has to return a function instead of a vector in his route definition. Check
(defmethod ig/init-key :reitit.routes/api
as an example.The solution is backward compatible: it still accepts vectors as a route definition, but in that case no reloading.
The reloading is by default enabled only in
:dev
profile.@yogthos , @nikolap please review before merging. I did some testing, but I'm not sure if there is a better/cleaner way to hook it up in integrant.