I’ve just checked-out the edge
project — impressive array of examples there! I was wondering if I can hot-replace handlers when connected via nRepl? It seems like I have to call (reset)
every time something changes…
What do you mean?
Say I want to redefined a resource by just evaluating a new get method or tweak some properties of the resource. I would like to just go to CIDER and eval the def
, and yada would pick it up on the next request.
(def hello-res
(resource {:id ::hi
:produces {:media-type "text/html"}
:methods {:get {:response #'hi-get}}
}))
I’ve found that doing #'hi-get
means I could re-define the hi-get
function. But I’d like to be able to re-defined the hello-res
resource as well.
For reference, here’s how hello-res
is used:
(defn -main []
(let [s (listener
["/"
[["hello" hello-res]
[true (as-resource nil)]]]
{:port 3000})]
(reset! server s)))
Using a var works for hello res too
#'hello-res
Hm, I got an exception when I tried to do that. Let me bring it back…
java.lang.ClassCastException: yada.resource.Resource cannot be cast to clojure.lang.IFn
at bidi.ring$eval39035$fn__39036.invoke(ring.clj:24)
at bidi.ring$eval39010$fn__39011$G__39001__39020.invoke(ring.clj:12)
at bidi.ring$make_handler$fn__39040.invoke(ring.clj:37)
at aleph.http.server$handle_request$fn__32260$f__17646__auto____32261.invoke(server.clj:157)
at clojure.lang.AFn.run(AFn.java:22)
at io.aleph.dirigiste.Executor$Worker$1.run(Executor.java:62)
at manifold.executor$thread_factory$reify__17528$f__17529.invoke(executor.clj:44)
at clojure.lang.AFn.run(AFn.java:22)
at java.lang.Thread.run(Thread.java:748)
This is when I actually visit the endpoint.
New code is
(defn -main []
(let [s (listener
["/"
[["hello" #'hello-res]
[true (as-resource nil)]]]
{:port 3000})]
(reset! server s)))
Does calling as-resource on it help?
You mean (as-resource #'hello-res)
? Checking…
Exception goes away, but changes aren’t being picked up.
We did this in the website, some variation of this works, @malcolmsparks
Thanks for the attention. It’s not a huge deal breaker but it would make for a great demo…