yada

orestis 2018-05-10T13:12:51.000509Z

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…

dominicm 2018-05-10T15:07:00.000316Z

What do you mean?

orestis 2018-05-10T15:31:25.000120Z

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.

orestis 2018-05-10T15:31:51.000821Z

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

orestis 2018-05-10T15:32:26.000252Z

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.

orestis 2018-05-10T15:33:01.000124Z

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

dominicm 2018-05-10T15:38:35.000204Z

Using a var works for hello res too

dominicm 2018-05-10T15:38:50.000542Z

#'hello-res

orestis 2018-05-10T15:41:54.000073Z

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

orestis 2018-05-10T15:43:24.000561Z

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)

orestis 2018-05-10T15:43:39.000104Z

This is when I actually visit the endpoint.

orestis 2018-05-10T15:44:12.000626Z

New code is

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

dominicm 2018-05-10T15:50:54.000146Z

Does calling as-resource on it help?

orestis 2018-05-10T15:51:31.000522Z

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

orestis 2018-05-10T15:53:40.000581Z

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

dominicm 2018-05-10T16:39:16.000736Z

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

orestis 2018-05-10T16:51:10.000515Z

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