diff --git a/bb.edn b/bb.edn index 7fc1d8d..87e7681 100644 --- a/bb.edn +++ b/bb.edn @@ -1,6 +1,6 @@ {:deps {io.github.babashka/sci.nrepl - #_{:local/root "../sci.nrepl"} - {:git/sha "8998f2a4fd25ff02474d7298253e91f059f482b2"}} + {:local/root "../sci.nrepl"} + #_{:git/sha "8998f2a4fd25ff02474d7298253e91f059f482b2"}} :tasks {:requires ([babashka.fs :as fs] diff --git a/resources/public/cljs/nrepl.cljs b/resources/public/cljs/nrepl.cljs index c28f9fd..a77d1d3 100644 --- a/resources/public/cljs/nrepl.cljs +++ b/resources/public/cljs/nrepl.cljs @@ -1,3 +1,13 @@ (ns nrepl) (+ 1 2 3) + +(-> + (js/document.getElementsByTagName "body") + first + (.append + (doto (js/document.createElement "p") + (.append + (js/document.createTextNode "there"))))) + +(js/alert "Isn't this cool? :)") diff --git a/src/scittle/nrepl.cljs b/src/scittle/nrepl.cljs index a96fa97..dfc7591 100644 --- a/src/scittle/nrepl.cljs +++ b/src/scittle/nrepl.cljs @@ -5,10 +5,7 @@ [scittle.core :refer [!last-ns eval-string !sci-ctx]])) (defn nrepl-websocket [] - (when (.-SCITTLE_BROWSER_REPL_PROXY_PORT js/window) - (set! (.-ws_nrepl js/window) - (new js/WebSocket "ws://localhost:1340/_nrepl")) - (.-ws_nrepl js/window))) + (.-ws_nrepl js/window)) (defn nrepl-reply [{:keys [id session]} payload] (.send (nrepl-websocket) @@ -31,12 +28,17 @@ (defn handle-nrepl-message [msg] (case (:op msg) :eval (handle-nrepl-eval msg) - :complete (nrepl-reply msg (completions (assoc msg :ctx @!sci-ctx))))) + :complete (let [completions (completions (assoc msg :ctx @!sci-ctx))] + (nrepl-reply msg completions)))) + +(when (.-SCITTLE_BROWSER_REPL_PROXY_PORT js/window) + (set! (.-ws_nrepl js/window) + (new js/WebSocket "ws://localhost:1340/_nrepl"))) (when-let [ws (nrepl-websocket)] + (prn :ws ws) (set! (.-onmessage ws) (fn [event] - (prn :event event) (handle-nrepl-message (edn/read-string (.-data event))))) (set! (.-onerror ws) (fn [event]