Skip to content

Instantly share code, notes, and snippets.

@bstro
Created March 9, 2014 23:05
Show Gist options
  • Save bstro/9456318 to your computer and use it in GitHub Desktop.
Save bstro/9456318 to your computer and use it in GitHub Desktop.
(ns switcher.core
(:require [cljs.core.async :refer [put! chan <! >!]])
(:require-macros [cljs.core.async.macros :refer [go go-loop]]))
(enable-console-print!)
(def NAME "s")
(def URL "https://nextdoor.com")
(defn getCookies []
(let [out (chan)]
(.get (.-cookies (.-chrome js/window)), #js {"name" NAME, "url" URL}, #(put! out (js->clj %)))
out))
(defn listen [el type]
(let [out (chan)]
(dommy/listen! (sel1 el) type #(put! out {:event %, :el el}))
out))
(defmulti handleUI :el)
(defmethod handleUI :#add [_]
(let [c (getCookies)
out (chan)]
(go (>! out (<! c))) out))
(defmethod handleUI :#reset [_]
_)
(let [add (listen :#add :click)
reset (listen :#reset :click)
input (cljs.core.async/merge [add reset])]
(go (while true
(prn (handleUI (<! input))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment