Skip to content

Commit 985ff1b

Browse files
Keep windows open when reloading page or showing different notebooks
1 parent 456fae4 commit 985ff1b

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/nextjournal/clerk/webserver.clj

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,22 @@
126126

127127
#_(pr-str (read-msg "#viewer-eval (resolve 'clojure.core/inc)"))
128128

129+
(defn update-window! [id state]
130+
(swap! !windows assoc id state)
131+
(broadcast! {:type :set-window-state! :id id :state state}))
132+
133+
(defn update-windows! []
134+
(doseq [[id state] @!windows]
135+
(update-window! id state)))
136+
137+
(defn close-window! [id]
138+
(swap! !windows dissoc id)
139+
(broadcast! {:type :close-window! :id id}))
140+
129141
(def ws-handlers
130-
{:on-open (fn [ch] (swap! !clients conj ch))
142+
{:on-open (fn [ch]
143+
(swap! !clients conj ch)
144+
(update-windows!))
131145
:on-close (fn [ch _reason] (swap! !clients disj ch))
132146
:on-receive (fn [sender-ch edn-string]
133147
(binding [*ns* (or (:ns @!doc)
@@ -193,15 +207,6 @@
193207

194208
#_(update-doc! (help-doc))
195209

196-
(defn update-window! [id state]
197-
(swap! !windows assoc id state)
198-
(broadcast! {:type :set-window-state! :id id :state state}))
199-
200-
(defn close-window! [id]
201-
(swap! !windows dissoc id)
202-
(broadcast! {:type :close-window! :id id}))
203-
204-
205210
(defn broadcast-status! [status]
206211
;; avoid editscript diff but use manual patch to just replace `:status` in doc
207212
(broadcast! {:type :patch-state! :patch [[[:status] :r status]]}))

0 commit comments

Comments
 (0)