<commit_before>(ns ajax-core-async.core
  (:require-macros [cljs.core.async.macros :refer [go]])
  (:require [goog.events :as events]
            [goog.dom :as dom]
            [cljs.core.async :refer [<! put! chan]])
  (:import goog.History
           goog.Uri
           goog.net.Jsonp))


(def search-url "http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=")

(def home-html
  (str "<h1>Search Wikipedia:</h1>"
       "<section>"
       "  <input id=\"query\" placeholder=\"Type your search...\" />"
       "  <button id=\"searchbutton\">Search</button>"
       "  <ul id=\"results\"></ul>"
       "</section>"))

(defn set-html! [el content]
  (set! (.-innerHTML el) content))

(defn build-html-list [items]
  (apply str (map #(str "<li>" % "</li>") items)))

(defn render-results [results]
  (let [article-names (second results)]
    (build-html-list article-names)))


(defn listen
  "Returns a core.async channel for events on an element."
  [el type]
  (let [out (chan)]
    (events/listen el type (fn [e] (put! out e)))
    out))

(defn do-jsonp [uri]
  (let [out (chan)
        req (Jsonp. (Uri. uri))]
    (.send req nil (fn [res] (put! out res)))
    out))


(defn handle-search-button-click [clicks]
  (go (while true
        (<! clicks)
        (let [uri     (str search-url (.-value (dom/getElement "query")))
              results (<! (do-jsonp uri))]
          (set-html! (dom/getElement "results")
                     (render-results results))))))

(defn main []
  (set-html! (dom/getElement "app") home-html)

  (let [clicks (listen (dom/getElement "searchbutton") (.-CLICK events/EventType))]
    (handle-search-button-click clicks)))<commit_msg>Specify event type<commit_after>(ns ajax-core-async.core
  (:require-macros [cljs.core.async.macros :refer [go]])
  (:require [goog.events :as events]
            [goog.events.EventType :as EventType]
            [goog.dom :as dom]
            [cljs.core.async :refer [<! put! chan]])
  (:import goog.History
           goog.Uri
           goog.net.Jsonp))


(def search-url "http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=")

(def home-html
  (str "<h1>Search Wikipedia:</h1>"
       "<section>"
       "  <input id=\"query\" placeholder=\"Type your search...\" />"
       "  <button id=\"searchbutton\">Search</button>"
       "  <ul id=\"results\"></ul>"
       "</section>"))

(defn set-html! [el content]
  (set! (.-innerHTML el) content))

(defn build-html-list [items]
  (apply str (map #(str "<li>" % "</li>") items)))

(defn render-results [results]
  (let [article-names (second results)]
    (build-html-list article-names)))


(defn listen
  "Returns a core.async channel for events on an element."
  [el type]
  (let [out (chan)]
    (events/listen el type (fn [e] (put! out e)))
    out))

(defn do-jsonp [uri]
  (let [out (chan)
        req (Jsonp. (Uri. uri))]
    (.send req nil (fn [res] (put! out res)))
    out))


(defn handle-search-button-click [clicks]
  (go (while true
        (<! clicks)
        (let [uri     (str search-url (.-value (dom/getElement "query")))
              results (<! (do-jsonp uri))]
          (set-html! (dom/getElement "results")
                     (render-results results))))))

(defn main []
  (set-html! (dom/getElement "app") home-html)

  (let [clicks (listen (dom/getElement "searchbutton") EventType/CLICK)]
    (handle-search-button-click clicks)))
{'fraction_non_alphanumeric': 0.18742690058479533, 'fraction_numerical': 0.0011695906432748538, 'mean_word_length': 2.6745435016111707, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 25, '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': '5005828', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1167, 'n_words': 299}