<commit_before>(ns replme.cljs.websocket
  (:require [cljs.core.async :refer [>! chan pub]]
            [cljs.reader :as reader])
  (:require-macros [cljs.core.async.macros :refer [go]]))

(enable-console-print!)

(defn new-socket
  [url]
  (js/WebSocket. url))

(defn close-socket [socket]
  (.close socket 1000))

(defn socket-send
  [socket msg]
  (.send socket msg))

(defn format-output
  [message]
  (if-not message
    "nil"
    message))

(defn handle-fn
  [out-chan]
  (fn [msg]
    (go (>! out-chan (-> (.-data msg)
                         reader/read-string
                         (update-in [:message] format-output))))))

(defn socket-out-pub
  [socket]
  (let [out-chan (chan)]
    (set! (.-onmessage socket) (handle-fn out-chan))
    (pub out-chan (fn [{:keys [destination]}] (println destination) destination))))
<commit_msg>Remove unneeded logging<commit_after>(ns replme.cljs.websocket
  (:require [cljs.core.async :refer [>! chan pub]]
            [cljs.reader :as reader])
  (:require-macros [cljs.core.async.macros :refer [go]]))

(enable-console-print!)

(defn new-socket
  [url]
  (js/WebSocket. url))

(defn close-socket [socket]
  (.close socket 1000))

(defn socket-send
  [socket msg]
  (.send socket msg))

(defn format-output
  [message]
  (if-not message
    "nil"
    message))

(defn handle-fn
  [out-chan]
  (fn [msg]
    (go (>! out-chan (-> (.-data msg)
                         reader/read-string
                         (update-in [:message] format-output))))))

(defn socket-out-pub
  [socket]
  (let [out-chan (chan)]
    (set! (.-onmessage socket) (handle-fn out-chan))
    (pub out-chan (fn [{:keys [destination]}] destination))))

{'fraction_non_alphanumeric': 0.17422434367541767, 'fraction_numerical': 0.00477326968973747, 'mean_word_length': 2.6695842450765865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3805801', 'n_tokens_mistral': 623, 'n_tokens_neox': 599, 'n_words': 144}