This commit is contained in:
Michiel Borkent 2022-05-16 21:41:41 +02:00
parent 8c2dfee980
commit a488900e23
3 changed files with 20 additions and 8 deletions

4
bb.edn
View file

@ -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]

View file

@ -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? :)")

View file

@ -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]