Skip to content

Instantly share code, notes, and snippets.

Created Mar 9, 2014
What would you like to do?
(ns switcher.core
(:require [cljs.core.async :refer [put! chan <! >!]])
(:require-macros [cljs.core.async.macros :refer [go go-loop]]))
(def NAME "s")
(def URL "")
(defn getCookies []
(let [out (chan)]
(.get (.-cookies (.-chrome js/window)), #js {"name" NAME, "url" URL}, #(put! out (js->clj %)))
(defn listen [el type]
(let [out (chan)]
(dommy/listen! (sel1 el) type #(put! out {:event %, :el el}))
(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