Last active
December 30, 2015 05:29
-
-
Save swannodette/7782780 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 react-cljs.core | |
(:require React)) | |
(enable-console-print!) | |
(declare render-ui) | |
(defn render-counter [id state root] | |
(let [cnt (or (get-in state [id :count]) 0)] | |
(React/DOM.div nil | |
(array | |
(React/DOM.label nil cnt) | |
(React/DOM.button | |
(js-obj "onClick" #(root (assoc-in state [id :count] (inc cnt)))) | |
"+") | |
(React/DOM.button | |
(js-obj "onClick" #(root (assoc-in state [id :count] (dec cnt)))) | |
"-"))))) | |
(defn render-ui [n] | |
(letfn [(root [state] | |
(React/renderComponent | |
(React/DOM.div nil | |
(into-array | |
(concat | |
[(React/DOM.h1 nil "A Counting Widget!")] | |
(map #(render-counter % state root) (range n))))) | |
js/document.body))] | |
(root (zipmap (range n) nil)))) | |
(render-ui 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(zipmap (range 10) nil) returns {}