(defn
init-watcher!
[]
(let
[protocol
(if (= (.-protocol js/location) "https:") "wss:" "ws:")
host
(-> js/window .-location .-host)
sock
(js/WebSocket. (str protocol "//" host "/watch"))]
(set!
(.-onopen sock)
(fn [event] (.send sock js/window.location.pathname)))
(set!
(.-onmessage sock)
(fn [event] (->> (.-data event) read-string (swap! *state merge))))
sock))