Use core.async to log added todos

This commit is contained in:
Nicholas Kariniemi 2013-07-27 00:07:31 +03:00
parent b56b50cd73
commit 87c7d1488b

View file

@ -1,6 +1,9 @@
(ns grub-client.core (ns grub-client.core
(:use-macros [dommy.macros :only [deftemplate sel1 node]]) ;(:use-macros [dommy.macros :only [deftemplate sel1 node]])
(:require [dommy.core :as dommy])) (:require [dommy.core :as dommy]
[cljs.core.async :as async :refer [<! >! chan close! timeout]])
(:require-macros [dommy.macros :refer [deftemplate sel1 node]]
[cljs.core.async.macros :as m :refer [go alt!]]))
(defn log [& args] (defn log [& args]
(apply #(.log js/console %) args)) (apply #(.log js/console %) args))
@ -30,9 +33,13 @@
[:input.span2#addGrubText {:type "text"}] [:input.span2#addGrubText {:type "text"}]
[:button.btn#addGrubButton {:type "button"} "Add"]]]]]) [:button.btn#addGrubButton {:type "button"} "Add"]]]]])
(defn onClicked [] (def add-grub-chan (chan))
(log "onClicked"))
(defn on-add-grub-clicked [& args]
(let [new-grub (dommy/value (sel1 :#addGrubText))]
(go (>! add-grub-chan new-grub))))
(dommy/prepend! (sel1 :body) (main-template test-grubs)) (dommy/prepend! (sel1 :body) (main-template test-grubs))
(dommy/listen! (sel1 :#addGrubButton) :click on-add-grub-clicked)
(dommy/listen! (sel1 :#addGrubButton) :click onClicked) (go (while true (log (<! add-grub-chan))))