Fork me on GitHub
#cursive
<
2020-10-30
>
simongray09:10:16

Is there a way to bind a key combo to send a piece of code to the REPL? I am developing a pedestal web service and it’s becoming a bit tiresome to navigate to the Rich comment block where my (restart-server) call is every time I make some changes… :S

3
simongray09:10:08

Awesomesauce!

simongray09:10:29

Thank you very much! Works perfect.

danieroux11:10:32

@U4P4NREBY it should not be necessary to call (restart-server) in pedestal. This is our dev-server:

(defn- route-fn
  "Use the deref of the namespace to get hot-reloaded namespaces."
  []
  (route/expand-routes
    (deref #'tech.matterindustries.titan.ion.api-gateway.service-handler/routes)))

(def interceptors
  (-> service-handler/service
    ; Get ion provider out of there
    (dissoc ::http/chain-provider)
    ; hot-reloaded-fn ftw!
    (assoc ::http/routes route-fn)
    (merge
      {::http/type  :jetty
       ::http/port  7001
       ::http/join? false})
    (http/default-interceptors)
    (http/dev-interceptors)))

danieroux11:10:01

Now everytime the route is hit, whatever code that was eval’ed in the REPL will get executed

simongray14:10:41

@U9E8C7QRJ Interesting. Can you explain a little how it works? I am currently working with something like

(defn start []
  (http/start (http/create-server service-map)))
but I don’t see any servers started in your snippet so I’m unsure what to do with it…?

danieroux10:11:37

@U4P4NREBY interceptors is the service-map in your start The important line that you need in your service map while developing, would be (assoc ::http/routes route-fn) . That route-fn dynamically expands the routes on every call - so point it to your routes

simongray11:11:39

Ah, I see. So #'tech.matterindustries.titan.ion.api-gateway.service-handler/routes is just a regular var that you’re deref’ing?

danieroux11:11:51

Yes, the app routing table

simongray11:11:54

Ok. Thanks! I think I'm just not familiar with the syntax here. Never deref'ed a var before. Anyway, I guess it wouldn't work without the deref since yo made it this way. I'm just not sure why.

roklenarcic12:10:37

I don’t know if this would be a cursive feature or nrepl feature, but how could I specify a snippet of code I want to run every time I reload a namespace while connected to REPL?

holyjak20:10:38

Set an environment variable / system property when starting REPL, have top-level expression wrapped in (if my-env-var-is-set...)?

roklenarcic00:10:46

I should have said reload any namespace instead of a namespace