<commit_before>(ns aspire.client
  (:require [clojure.browser.repl :as repl]
            [clojure.browser.net :as cb-net]
            [clojure.browser.event :as cb-event]
            [cljs.reader :as edn]
            [dommy.core :as dommy]
            [dommy.attrs :as d-attrs]
            [goog.string :as gstring]
            [goog.string.format :as gformat]
            [aspire.model :as a-mdl]
            )
  (:use-macros
   [dommy.macros :only [by-id sel1]]))

(repl/connect "http://localhost:9000/repl")
(def api-uri "http://localhost:4001/api")

;; Callbacks
;; --------------------------------------------------
;; If possible we'll get by with one err callback and one success
;; callback for XHR, and use client-side routing and core.async
;; instead of multiple XHR callbacks.
(defn srv-callback-err [ev]
  (.log js/console "Error: " ev))

(defn srv-callback-success [ev]
  (let [response-text (.getResponseText (.-target ev))]
    (.log js/console (:now (edn/read-string response-text)))
    (dommy/replace! (sel1 :#loading) [:p#loading (gstring/format "This is now: %s" (:now (edn/read-string response-text)))])))

;; xhr
;; --------------------------------------------------
;; Create and keep one xhr object that knows about our two XHR callbacks.
(def xhr (cb-net/xhr-connection.)) ; additional state!
(cb-event/listen xhr :error srv-callback-err)
(cb-event/listen xhr :success srv-callback-success)

(defn xhr-fetch!
  "Fetch the specified uri.
   This fn will change as we add client-side routes and core.async."
  [uri]
  (cb-net/transmit xhr uri))

(defn handle-click
  "Shallow demo of click-handling fn."
  []
  (js/alert "Hello!")
  (xhr-fetch! api-uri))

(defn poll
  "Request new data every 10 seconds, because we can." 
  []
  (let [timer (goog.Timer. 10000)]
    (do (xhr-fetch! api-uri)
        (. timer (start))
        (cb-event/listen timer goog.Timer/TICK #(xhr-fetch! api-uri)))))<commit_msg>Clean up deps, move callbacks out to separate source file.<commit_after>(ns aspire.client
  (:require [clojure.browser.repl :as repl]
            [clojure.browser.net :as cb-net]
            [clojure.browser.event :as cb-event]
            [hickory.core :as hickory]
            [goog.string :as gstring]
            [goog.string.format :as gformat]
            [aspire.model :as a-mdl]
            [aspire.callbacks :as a-cb]
            ))

(repl/connect "http://localhost:9000/repl")
(def api-uri "http://localhost:4001/api")

;; xhr
;; --------------------------------------------------
;; Create and keep one xhr object that knows about our two XHR callbacks.
(def xhr (cb-net/xhr-connection.)) ; additional state!
(cb-event/listen xhr :error a-cb/err)
(cb-event/listen xhr :success a-cb/success)

(defn xhr-fetch!
  "Fetch the specified uri.
   This fn will change as we add client-side routes and core.async."
  [uri]
  (cb-net/transmit xhr uri))

(defn handle-click
  "Shallow demo of click-handling fn."
  []
  (js/alert "Hello!")
  (xhr-fetch! api-uri))

(defn poll
  "Request new data every 10 seconds, because we can." 
  []
  (let [timer (goog.Timer. 10000)]
    (do (xhr-fetch! api-uri)
        (. timer (start))
        (cb-event/listen timer goog.Timer/TICK #(xhr-fetch! api-uri)))))
{'fraction_non_alphanumeric': 0.18728682170542635, 'fraction_numerical': 0.00992248062015504, 'mean_word_length': 2.356919875130073, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4202078', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1082, 'n_words': 307}