-
-
Save swlabrtyr/29d0fcd6a740a3807f4a6587e59955df 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
(defn toggle-class [a k class1 class2] | |
(println "test") | |
(if (= (@a k) class1) | |
(swap! a assoc k class2) | |
(swap! a assoc k class1))) | |
(def local-state (r/atom {:class "note note-off"})) | |
(toggle-class local-state :class "note note-off" "note note-on") ;; works here | |
(@local-state :class) | |
(defn render-note [] | |
(fn [text key] | |
(let [local-state (r/atom {:class "note note-off"})] | |
[:div {:key key | |
:on-click (fn [_] (toggle-class local-state :class "note note-off" "note note-on")) ;; doesn't work here | |
:class (@local-state :class)} | |
(str text (@local-state :class))]))) | |
(defn render-notes [] | |
[:div {:id "notes-container" :class "notes-container"} | |
(doall | |
(for [n (range 1 65)] | |
((render-note) n n)))]) | |
(r/render-component [render-notes] | |
(. js/document (getElementById "app"))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment