← Back to home

ClojureScript nREPL Diary — 9

Ok, here’s how I managed to determine a ClojureScript session in an nREPL middleware:

(defn my-middleware [handler]
  (fn [{:keys [session] :as msg}]
    (when (and session
               (not (string? session))
               (@session #'piggieback/*cljs-repl-env*))
      (println "Bingo! I'm in a ClojureScript session"))
    (handler msg)))

(set-descriptor! #'my-middleware
                 {:requires #{"session"}
                  :expects #{#'piggieback/wrap-cljs-repl}})

I was banging my head against the wall because every open source middleware I saw seemed to receive an atom as a session parameter. I was getting a stringified ID at all times. The solution was to write a proper descriptor for the middleware that would depend on the session and that would line after wrap-cljs-repl. After that I started to get an atom as well, and then everything worked.

Last edited on Aug 8, 2019