Created
March 9, 2014 23:05
-
-
Save bstro/9456318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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