Skip to content

Instantly share code, notes, and snippets.

@swlabrtyr

swlabrtyr/.cljs Secret

Created November 1, 2017 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swlabrtyr/29d0fcd6a740a3807f4a6587e59955df to your computer and use it in GitHub Desktop.
Save swlabrtyr/29d0fcd6a740a3807f4a6587e59955df to your computer and use it in GitHub Desktop.
(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