Fork me on GitHub
#yada
<
2018-05-10
>
orestis13:05:51

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…

dominicm15:05:00

What do you mean?

orestis15:05:25

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.

orestis15:05:51

(def hello-res
  (resource {:id ::hi
             :produces {:media-type "text/html"}
             :methods {:get {:response #'hi-get}}
             }))

orestis15:05:26

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.

orestis15:05:01

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)))

dominicm15:05:35

Using a var works for hello res too

dominicm15:05:50

#'hello-res

orestis15:05:54

Hm, I got an exception when I tried to do that. Let me bring it back…

orestis15:05:24

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)

orestis15:05:39

This is when I actually visit the endpoint.

orestis15:05:12

New code is

(defn -main []
  (let [s (listener
           ["/"
            [["hello" #'hello-res]
             [true (as-resource nil)]]]
           {:port 3000})]
    (reset! server s)))

dominicm15:05:54

Does calling as-resource on it help?

orestis15:05:31

You mean (as-resource #'hello-res) ? Checking…

orestis15:05:40

Exception goes away, but changes aren’t being picked up.

dominicm16:05:16

We did this in the website, some variation of this works, @U050CTFRT

orestis16:05:10

Thanks for the attention. It’s not a huge deal breaker but it would make for a great demo…