Created
July 4, 2015 23:20
-
-
Save mhuebert/6fd589fbf4362a51d377 to your computer and use it in GitHub Desktop.
Reagent Cursors Test
This file contains hidden or 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 app.layout | |
(:require | |
[reagent.core :as r] | |
[reagent.cursor :refer [cursor]])) | |
(defonce my-state (r/atom {1 "aaa" | |
2 "bbb"})) | |
(defn display-item [item-cursor id] | |
(fn [] | |
(prn (str "Re-rendering item #" id)) | |
[:span (str @item-cursor)])) | |
(defn modify-item-state [id] | |
[:a {:on-click #(swap! my-state assoc id (rand-int 1000))} (str "Change " id)]) | |
(defn test-div [] | |
[:div | |
[display-item (cursor [1] my-state) 1] | |
[modify-item-state 1] | |
[display-item (cursor [2] my-state) 2] | |
[modify-item-state 2]]) | |
(defn app-generalized [] | |
[:div | |
[display-cell 1] | |
[display-cell 2] | |
[display-cell 3] | |
[display-cell 4] | |
[test-div]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment