kit
kit copied to clipboard
Autoreload on file change or on evalutation
Is it possible to autoreload or auto-reset when a file changes, or when form is evaluated in a namespace?
The closest would be to call (user/refresh)
from the REPL.
Does that need to be called on each change?
Yeah, you'd have to call it explicitly when you want the REPL state refreshed.
Is it possible to have this called on file change, or when something is evaluated in the repl?
Generally, that wouldn't be the desired behavior. You shouldn't have to reload the entire REPL state any time you evaluate something in the REPL. Typically, it's best to do a full reload explicitly with a command instead of having it run automatically as it's a slower operation and it can break the REPL state if files aren't in a good state.
That was my first thought initially too. But in my project if I evaluate a function that returns some hiccup, that change isn't reflected when I reload the browser page. Does that mean my project is misconfigured, or is this the expected behavior?
This is more of a reitit
problem than kit
. Once routes are defined, the handler is bound to the route. Even if you recompile the handler function, reitit will still use the old one.
One workaround is that you define your routes to use functions.
For example, instead of the following:
(defn ui-routes [_opts]
[["/" {:get home}]
["/clicked" {:post clicked}]])
you wrap your handlers with function in your route definitions
(defn ui-routes [_opts]
[["/" {:get #(home %)}]
["/clicked" {:post #(clicked %)}]])
This is not elegant, but it works.
The right fix would be to implement a solution from reitit directly in kit
. Basically, having one non-efficient but reloadable router for development, and one non-reloadable but efficient for production.
I think that would be a useful change to make. @nikolap thoughts?
Great find and makes sense to me, thanks for the research and recommendation.
Would welcome a PR. Else I can look at it in late-July.
Haven't forgotten this issue! Only just found the time to look at it :)
Do we still need to figure out a fix here?
I haven't tested master, but for my day to day workflow I still need to reset on each and every change.