wip
This commit is contained in:
parent
12b96602a3
commit
8c2dfee980
4 changed files with 35 additions and 11 deletions
20
bb.edn
20
bb.edn
|
|
@ -1,4 +1,8 @@
|
|||
{:tasks
|
||||
{:deps {io.github.babashka/sci.nrepl
|
||||
#_{:local/root "../sci.nrepl"}
|
||||
{:git/sha "8998f2a4fd25ff02474d7298253e91f059f482b2"}}
|
||||
|
||||
:tasks
|
||||
{:requires ([babashka.fs :as fs]
|
||||
[cheshire.core :as json]
|
||||
[babashka.process :as p :refer [process]])
|
||||
|
|
@ -8,8 +12,20 @@
|
|||
(fs/delete-tree ".cpcache")
|
||||
(fs/delete-tree ".shadow-cljs"))}
|
||||
|
||||
shadow:watch {:doc "Development build. Starts webserver and watches for changes."
|
||||
:task (clojure "-M:dev -m shadow.cljs.devtools.cli watch main")}
|
||||
|
||||
browser-nrepl {:doc "Start browser nREPL"
|
||||
:requires ([sci.nrepl.browser-proxy :as bp])
|
||||
:task (do (bp/start-browser-nrepl! {:port 1339})
|
||||
(bp/serve! {:port 1340})
|
||||
(println "Started browser nREPL on port 1339")
|
||||
(deref (promise)))}
|
||||
|
||||
-dev {:depends [shadow:watch browser-nrepl]}
|
||||
|
||||
dev {:doc "Development build. Starts webserver and watches for changes."
|
||||
:task (clojure "-M:dev -m shadow.cljs.devtools.cli watch main")}
|
||||
:task (run '-dev {:parallel true})}
|
||||
|
||||
prod {:doc "Builds production artifacts."
|
||||
:task (clojure {:extra-env {"SCI_ELIDE_VARS" "true"}}
|
||||
|
|
|
|||
3
resources/public/cljs/nrepl.cljs
Normal file
3
resources/public/cljs/nrepl.cljs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(ns nrepl)
|
||||
|
||||
(+ 1 2 3)
|
||||
|
|
@ -3,7 +3,9 @@
|
|||
<head>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<script src="js/scittle.js" type="application/javascript"></script>
|
||||
<script>var SCITTLE_BROWSER_REPL_PROXY_PORT = 1340;</script>
|
||||
<script src="js/scittle.nrepl.js" type="application/javascript"></script>
|
||||
<script type="application/x-scittle" src="cljs/nrepl.cljs"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Scittle</h1>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@
|
|||
[scittle.core :refer [!last-ns eval-string !sci-ctx]]))
|
||||
|
||||
(defn nrepl-websocket []
|
||||
(.-ws_nrepl js/window))
|
||||
(when (.-SCITTLE_BROWSER_REPL_PROXY_PORT js/window)
|
||||
(set! (.-ws_nrepl js/window)
|
||||
(new js/WebSocket "ws://localhost:1340/_nrepl"))
|
||||
(.-ws_nrepl js/window)))
|
||||
|
||||
(defn nrepl-reply [{:keys [id session]} payload]
|
||||
(.send (nrepl-websocket)
|
||||
|
|
@ -30,11 +33,11 @@
|
|||
:eval (handle-nrepl-eval msg)
|
||||
:complete (nrepl-reply msg (completions (assoc msg :ctx @!sci-ctx)))))
|
||||
|
||||
(defn ^:export init-nrepl []
|
||||
(let [ws (nrepl-websocket)]
|
||||
(set! (.-onmessage ws)
|
||||
(fn [event]
|
||||
(handle-nrepl-message (edn/read-string (.-data event)))))
|
||||
(set! (.-onerror ws)
|
||||
(fn [event]
|
||||
(js/console.log event)))))
|
||||
(when-let [ws (nrepl-websocket)]
|
||||
(set! (.-onmessage ws)
|
||||
(fn [event]
|
||||
(prn :event event)
|
||||
(handle-nrepl-message (edn/read-string (.-data event)))))
|
||||
(set! (.-onerror ws)
|
||||
(fn [event]
|
||||
(js/console.log event))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue